﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VSWClient.Tcp;
using VSWClient.Utility;
using System.Data;
using System.Collections.ObjectModel;
using VSWClient.Pages.DataGridClass;
using Oracle.ManagedDataAccess.Client;
using VSWClient.Tables;
using VSWClient.Pages.Tables.L2PDB;
using System.Threading;
using System.Drawing;

namespace VSWClient.Pages
{
	/// <summary>
	/// Page_Order.xaml interaction logic
	/// </summary>
	public partial class Page_Task : Page
	{
		TcpClient client;
		ObservableCollection<Tasks> generalNaturalTasks = new ObservableCollection<Tasks>();
		ObservableCollection<Strips> generalNaturalStrips = new ObservableCollection<Strips>();
		ObservableCollection<Tasks> editTasks = new ObservableCollection<Tasks>();
		ObservableCollection<Strips> editStrips = new ObservableCollection<Strips>();
		public string generalOrEditStrip = "allStrip";
		public string generalOrEditTask = "allTask";
		string buttonSaveRecipe_EditorNew = "";
		string buttonSaveBatchRule_EditorNew = "";
		string buttonSaveStripRule_EditorNew = "";
		DataTable editTaskStripTable = new DataTable();
		DataTable batchSampleRuleDetailDataTable;
		DataTable stripSampleRuleDetailDataTable;
		DataTable dataTableStripInfo;
		DataTable dataTableTaskInfo;

		public int generalTask_Index = 1;//generaltask table data current page
		public int generalTask_Pagenum = 20;//numbers of generaltask table data per page
		public bool generalTask_index_isChange = true;
		public int taskTask_Index = 1;//tasktask table data current page
		public int taskTask_Pagenum = 20;//numbers of tasktask table data per page
		public bool taskTask_index_isChange = true;
		public string taskPageSql = "select * from (select ROWNUM rn, d.* from (select * from TASK_INFO order by update_Time) d)";
		public string taskTaskMode = "GeneralTaskDetail";

		public int generalStrip_Index = 1;//generalstrip tabe data current page
		public int generalStrip_Pagenum = 20;//numbers of generalstriptable data per page
		public bool generalStrip_index_isChange = true;
		public string generaStripTaskNo = "";
		public int taskStrip_Index = 1;//taskstrip table data current page
		public int taskStrip_Pagenum = 20;//numbers of taskstrip table data per page
		public bool taskStrip_index_isChange = true;
		public string taskStripTaskNo = "";
		public int taskEditStrip_Index = 1;//PopupTask_taskstrip table data current page
		public int taskEditStrip_Pagenum = 20;//numbers of PopupTask_taskstrip table data per page
		public bool taskEditStrip_index_isChange = true;
		public string popupTaskStripTaskNo = "";
		public string taskStripMode = "GeneralStripDetail";

		public int recipeDetail_Index = 1;//recipedetail table data current page
		public int recipeDetail_Pagenum = 20;//numbers of recipedetail table data per page
		public bool recipeDetail_index_isChange = true;
		public string recipeDetailPageSql = "";
		public int recipeBind_Index = 1;//recipeBind table data current page
		public int recipeBind_Pagenum = 20;//numebers of recipeBind table data per page
		public bool recipeBind_index_isChange = true;
		public string popupRecipePageSql = "";
		public string recipeDetailMode = "RecipeDetail";

		public int batchSampleRuleDetail_Index = 1;//batchSampleRuledetail table data current page
		public int batchSampleRuleDetail_Pagenum = 20;//numbers of batchSampleRuledetail table data per page
		public bool batchSampleRuleDetail_index_isChange = true;
		public int batchSampleRuleBind_Index = 1;//batchSampleRulebind table data current page
		public int batchSampleRuleBind_Pagenum = 20;//numbers of batchSampleRulebindtable data per page
		public bool batchSampleRuleBind_index_isChange = true;
		public string batchSampleRuleDetailMode = "BatchSampleRuleDetail";

		public int stripSampleRuleDetail_Index = 1;//stripSampleRuledetail table data current page 
		public int stripSampleRuleDetail_Pagenum = 20;//numbers of stripSampleRuledetail table data per page
		public bool stripSampleRuleDetail_index_isChange = true;
		public int stripSampleRuleBind_Index = 1;//stripSampleRuleBind table data current page 
		public int stripSampleRuleBind_Pagenum = 20;//numbers of stripSampleRuleBind table data per page
		public bool stripSampleRuleBind_index_isChange = true;
		public string stripSampleRuleDetailMode = "StripSampleRuleDetail";
		Dictionary<string, string> dictionaryProStandard = new Dictionary<string, string>();
		Dictionary<string, string> dictionaryComboBoxTaskStatus = new Dictionary<string, string>();
		Dictionary<string, string> dictionaryDurClassAndSteelGrade = new Dictionary<string, string>();
		string btnSaveOrder = "";
		string btnSaveStrip = "";
		string btnSaveProStandard = "";

		public Page_Task(TcpClient tcp)
		{
			InitializeComponent();
			client = tcp;
			client.SendMessage(Identity.definedCommand, Identity.initPageTask, "");			
		}

		private void Page_Loaded(object sender, RoutedEventArgs e)
		{

			#region dictionaryDurClassAndSteelGrade add item
			dictionaryDurClassAndSteelGrade.Clear();
			dictionaryDurClassAndSteelGrade.Add("H40", "11");
			dictionaryDurClassAndSteelGrade.Add("J55", "12");
			dictionaryDurClassAndSteelGrade.Add("K55", "13");
			dictionaryDurClassAndSteelGrade.Add("K72", "14");
			dictionaryDurClassAndSteelGrade.Add("N80-1", "15");
			dictionaryDurClassAndSteelGrade.Add("N80-Q", "16");
			dictionaryDurClassAndSteelGrade.Add("R95", "17");
			dictionaryDurClassAndSteelGrade.Add("M65", "21");
			dictionaryDurClassAndSteelGrade.Add("L80-1", "22");
			dictionaryDurClassAndSteelGrade.Add("L80-9Cr", "23");
			dictionaryDurClassAndSteelGrade.Add("L80-13Cr", "24");
			dictionaryDurClassAndSteelGrade.Add("C90-1", "25");
			dictionaryDurClassAndSteelGrade.Add("C90-2", "26");
			dictionaryDurClassAndSteelGrade.Add("C95", "27");
			dictionaryDurClassAndSteelGrade.Add("T95-1", "28");
			dictionaryDurClassAndSteelGrade.Add("T95-2", "29");
			dictionaryDurClassAndSteelGrade.Add("P110", "31");
			dictionaryDurClassAndSteelGrade.Add("Q125-1", "41");
			dictionaryDurClassAndSteelGrade.Add("Q125-2", "42");
			dictionaryDurClassAndSteelGrade.Add("Q125-3", "43");
			dictionaryDurClassAndSteelGrade.Add("Q125-4", "44");
			dictionaryDurClassAndSteelGrade.Add("Q135", "45");
			dictionaryDurClassAndSteelGrade.Add("Д", "51");
			dictionaryDurClassAndSteelGrade.Add("К", "52");
			dictionaryDurClassAndSteelGrade.Add("Е", "53");
			dictionaryDurClassAndSteelGrade.Add("Л", "54");
			dictionaryDurClassAndSteelGrade.Add("М", "55");
			dictionaryDurClassAndSteelGrade.Add("Р", "56");
			dictionaryDurClassAndSteelGrade.Add("Т", "57");
			dictionaryDurClassAndSteelGrade.Add("L175 or A25", "61");
			dictionaryDurClassAndSteelGrade.Add("L210 or A", "62");
			dictionaryDurClassAndSteelGrade.Add("L245 or B", "63");
			dictionaryDurClassAndSteelGrade.Add("L290 or X42", "64");
			dictionaryDurClassAndSteelGrade.Add("L320 or X46", "65");
			dictionaryDurClassAndSteelGrade.Add("L360 or X52", "66");
			dictionaryDurClassAndSteelGrade.Add("L390 or X56", "67");
			dictionaryDurClassAndSteelGrade.Add("L415 or X60", "68");
			dictionaryDurClassAndSteelGrade.Add("L450 or X65", "69");
			dictionaryDurClassAndSteelGrade.Add("L486 or X70", "70");
			dictionaryDurClassAndSteelGrade.Add("L245N or BN", "73");
			dictionaryDurClassAndSteelGrade.Add("L290N or X42N", "74");
			dictionaryDurClassAndSteelGrade.Add("L320N or X46N", "75");
			dictionaryDurClassAndSteelGrade.Add("L360N or X52N", "76");
			dictionaryDurClassAndSteelGrade.Add("L390N or X56N", "77");
			dictionaryDurClassAndSteelGrade.Add("L415N or X60N", "78");
			dictionaryDurClassAndSteelGrade.Add("L245Q or BQ", "83");
			dictionaryDurClassAndSteelGrade.Add("L290Q or X42Q", "84");
			dictionaryDurClassAndSteelGrade.Add("L320Q or X46Q", "85");
			dictionaryDurClassAndSteelGrade.Add("L360Q or X52Q", "86");
			dictionaryDurClassAndSteelGrade.Add("L390Q or X56Q", "87");
			dictionaryDurClassAndSteelGrade.Add("L415Q or X60Q", "88");
			#endregion


			#region comboBox_PipeDurClass add item
			comboBox_PipeDurClass.Items.Clear();
			comboBox_PipeDurClass.Items.Add("H40");
			comboBox_PipeDurClass.Items.Add("J55");
			comboBox_PipeDurClass.Items.Add("K55");
			comboBox_PipeDurClass.Items.Add("K72");
			comboBox_PipeDurClass.Items.Add("N80-1");
			comboBox_PipeDurClass.Items.Add("N80-Q");
			comboBox_PipeDurClass.Items.Add("R95");
			comboBox_PipeDurClass.Items.Add("M65");
			comboBox_PipeDurClass.Items.Add("L80-1");
			comboBox_PipeDurClass.Items.Add("L80-9Cr");
			comboBox_PipeDurClass.Items.Add("L80-13Cr");
			comboBox_PipeDurClass.Items.Add("C90-1");
			comboBox_PipeDurClass.Items.Add("C90-2");
			comboBox_PipeDurClass.Items.Add("C95");
			comboBox_PipeDurClass.Items.Add("T95-1");
			comboBox_PipeDurClass.Items.Add("T95-2");
			comboBox_PipeDurClass.Items.Add("P110");
			comboBox_PipeDurClass.Items.Add("Q125-1");
			comboBox_PipeDurClass.Items.Add("Q125-2");
			comboBox_PipeDurClass.Items.Add("Q125-3");
			comboBox_PipeDurClass.Items.Add("Q125-4");
			comboBox_PipeDurClass.Items.Add("Q135");
			comboBox_PipeDurClass.Items.Add("Д");
			comboBox_PipeDurClass.Items.Add("К");
			comboBox_PipeDurClass.Items.Add("Е");
			comboBox_PipeDurClass.Items.Add("Л");
			comboBox_PipeDurClass.Items.Add("М");
			comboBox_PipeDurClass.Items.Add("Р");
			comboBox_PipeDurClass.Items.Add("Т");
			comboBox_PipeDurClass.Items.Add("L175 or A25");
			comboBox_PipeDurClass.Items.Add("L210 or A");
			comboBox_PipeDurClass.Items.Add("L245 or B");
			comboBox_PipeDurClass.Items.Add("L290 or X42");
			comboBox_PipeDurClass.Items.Add("L320 or X46");
			comboBox_PipeDurClass.Items.Add("L360 or X52");
			comboBox_PipeDurClass.Items.Add("L390 or X56");
			comboBox_PipeDurClass.Items.Add("L415 or X60");
			comboBox_PipeDurClass.Items.Add("L450 or X65");
			comboBox_PipeDurClass.Items.Add("L486 or X70");
			comboBox_PipeDurClass.Items.Add("L245N or BN");
			comboBox_PipeDurClass.Items.Add("L290N or X42N");
			comboBox_PipeDurClass.Items.Add("L320N or X46N");
			comboBox_PipeDurClass.Items.Add("L360N or X52N");
			comboBox_PipeDurClass.Items.Add("L390N or X56N");
			comboBox_PipeDurClass.Items.Add("L415N or X60N");
			comboBox_PipeDurClass.Items.Add("L245Q or BQ");
			comboBox_PipeDurClass.Items.Add("L290Q or X42Q");
			comboBox_PipeDurClass.Items.Add("L320Q or X46Q");
			comboBox_PipeDurClass.Items.Add("L360Q or X52Q");
			comboBox_PipeDurClass.Items.Add("L390Q or X56Q");
			comboBox_PipeDurClass.Items.Add("L415Q or X60Q");
			#endregion


			#region comboBox_PipeSteelGrade add item
			comboBox_PipeSteelGrade.Items.Clear();
			comboBox_PipeSteelGrade.Items.Add("H40");
			comboBox_PipeSteelGrade.Items.Add("J55");
			comboBox_PipeSteelGrade.Items.Add("K55");
			comboBox_PipeSteelGrade.Items.Add("K72");
			comboBox_PipeSteelGrade.Items.Add("N80-1");
			comboBox_PipeSteelGrade.Items.Add("N80-Q");
			comboBox_PipeSteelGrade.Items.Add("R95");
			comboBox_PipeSteelGrade.Items.Add("M65");
			comboBox_PipeSteelGrade.Items.Add("L80-1");
			comboBox_PipeSteelGrade.Items.Add("L80-9Cr");
			comboBox_PipeSteelGrade.Items.Add("L80-13Cr");
			comboBox_PipeSteelGrade.Items.Add("C90-1");
			comboBox_PipeSteelGrade.Items.Add("C90-2");
			comboBox_PipeSteelGrade.Items.Add("C95");
			comboBox_PipeSteelGrade.Items.Add("T95-1");
			comboBox_PipeSteelGrade.Items.Add("T95-2");
			comboBox_PipeSteelGrade.Items.Add("P110");
			comboBox_PipeSteelGrade.Items.Add("Q125-1");
			comboBox_PipeSteelGrade.Items.Add("Q125-2");
			comboBox_PipeSteelGrade.Items.Add("Q125-3");
			comboBox_PipeSteelGrade.Items.Add("Q125-4");
			comboBox_PipeSteelGrade.Items.Add("Q135");
			comboBox_PipeSteelGrade.Items.Add("Д");
			comboBox_PipeSteelGrade.Items.Add("К");
			comboBox_PipeSteelGrade.Items.Add("Е");
			comboBox_PipeSteelGrade.Items.Add("Л");
			comboBox_PipeSteelGrade.Items.Add("М");
			comboBox_PipeSteelGrade.Items.Add("Р");
			comboBox_PipeSteelGrade.Items.Add("Т");
			comboBox_PipeSteelGrade.Items.Add("L175 or A25");
			comboBox_PipeSteelGrade.Items.Add("L210 or A");
			comboBox_PipeSteelGrade.Items.Add("L245 or B");
			comboBox_PipeSteelGrade.Items.Add("L290 or X42");
			comboBox_PipeSteelGrade.Items.Add("L320 or X46");
			comboBox_PipeSteelGrade.Items.Add("L360 or X52");
			comboBox_PipeSteelGrade.Items.Add("L390 or X56");
			comboBox_PipeSteelGrade.Items.Add("L415 or X60");
			comboBox_PipeSteelGrade.Items.Add("L450 or X65");
			comboBox_PipeSteelGrade.Items.Add("L486 or X70");
			comboBox_PipeSteelGrade.Items.Add("L245N or BN");
			comboBox_PipeSteelGrade.Items.Add("L290N or X42N");
			comboBox_PipeSteelGrade.Items.Add("L320N or X46N");
			comboBox_PipeSteelGrade.Items.Add("L360N or X52N");
			comboBox_PipeSteelGrade.Items.Add("L390N or X56N");
			comboBox_PipeSteelGrade.Items.Add("L415N or X60N");
			comboBox_PipeSteelGrade.Items.Add("L245Q or BQ");
			comboBox_PipeSteelGrade.Items.Add("L290Q or X42Q");
			comboBox_PipeSteelGrade.Items.Add("L320Q or X46Q");
			comboBox_PipeSteelGrade.Items.Add("L360Q or X52Q");
			comboBox_PipeSteelGrade.Items.Add("L390Q or X56Q");
			comboBox_PipeSteelGrade.Items.Add("L415Q or X60Q");
			#endregion

			#region comboBox_stripDurClass add item
			comboBox_stripDurClass.Items.Clear();
			comboBox_stripDurClass.Items.Add("H40");
			comboBox_stripDurClass.Items.Add("J55");
			comboBox_stripDurClass.Items.Add("K55");
			comboBox_stripDurClass.Items.Add("K72");
			comboBox_stripDurClass.Items.Add("N80-1");
			comboBox_stripDurClass.Items.Add("N80-Q");
			comboBox_stripDurClass.Items.Add("R95");
			comboBox_stripDurClass.Items.Add("M65");
			comboBox_stripDurClass.Items.Add("L80-1");
			comboBox_stripDurClass.Items.Add("L80-9Cr");
			comboBox_stripDurClass.Items.Add("L80-13Cr");
			comboBox_stripDurClass.Items.Add("C90-1");
			comboBox_stripDurClass.Items.Add("C90-2");
			comboBox_stripDurClass.Items.Add("C95");
			comboBox_stripDurClass.Items.Add("T95-1");
			comboBox_stripDurClass.Items.Add("T95-2");
			comboBox_stripDurClass.Items.Add("P110");
			comboBox_stripDurClass.Items.Add("Q125-1");
			comboBox_stripDurClass.Items.Add("Q125-2");
			comboBox_stripDurClass.Items.Add("Q125-3");
			comboBox_stripDurClass.Items.Add("Q125-4");
			comboBox_stripDurClass.Items.Add("Q135");
			comboBox_stripDurClass.Items.Add("Д");
			comboBox_stripDurClass.Items.Add("К");
			comboBox_stripDurClass.Items.Add("Е");
			comboBox_stripDurClass.Items.Add("Л");
			comboBox_stripDurClass.Items.Add("М");
			comboBox_stripDurClass.Items.Add("Р");
			comboBox_stripDurClass.Items.Add("Т");
			comboBox_stripDurClass.Items.Add("L175 or A25");
			comboBox_stripDurClass.Items.Add("L210 or A");
			comboBox_stripDurClass.Items.Add("L245 or B");
			comboBox_stripDurClass.Items.Add("L290 or X42");
			comboBox_stripDurClass.Items.Add("L320 or X46");
			comboBox_stripDurClass.Items.Add("L360 or X52");
			comboBox_stripDurClass.Items.Add("L390 or X56");
			comboBox_stripDurClass.Items.Add("L415 or X60");
			comboBox_stripDurClass.Items.Add("L450 or X65");
			comboBox_stripDurClass.Items.Add("L486 or X70");
			comboBox_stripDurClass.Items.Add("L245N or BN");
			comboBox_stripDurClass.Items.Add("L290N or X42N");
			comboBox_stripDurClass.Items.Add("L320N or X46N");
			comboBox_stripDurClass.Items.Add("L360N or X52N");
			comboBox_stripDurClass.Items.Add("L390N or X56N");
			comboBox_stripDurClass.Items.Add("L415N or X60N");
			comboBox_stripDurClass.Items.Add("L245Q or BQ");
			comboBox_stripDurClass.Items.Add("L290Q or X42Q");
			comboBox_stripDurClass.Items.Add("L320Q or X46Q");
			comboBox_stripDurClass.Items.Add("L360Q or X52Q");
			comboBox_stripDurClass.Items.Add("L390Q or X56Q");
			comboBox_stripDurClass.Items.Add("L415Q or X60Q");
			#endregion


			

			#region comboBox_stripSteelGrade add item
			comboBox_stripSteelGrade.Items.Clear();
			comboBox_stripSteelGrade.Items.Add("H40");
			comboBox_stripSteelGrade.Items.Add("J55");
			comboBox_stripSteelGrade.Items.Add("K55");
			comboBox_stripSteelGrade.Items.Add("K72");
			comboBox_stripSteelGrade.Items.Add("N80-1");
			comboBox_stripSteelGrade.Items.Add("N80-Q");
			comboBox_stripSteelGrade.Items.Add("R95");
			comboBox_stripSteelGrade.Items.Add("M65");
			comboBox_stripSteelGrade.Items.Add("L80-1");
			comboBox_stripSteelGrade.Items.Add("L80-9Cr");
			comboBox_stripSteelGrade.Items.Add("L80-13Cr");
			comboBox_stripSteelGrade.Items.Add("C90-1");
			comboBox_stripSteelGrade.Items.Add("C90-2");
			comboBox_stripSteelGrade.Items.Add("C95");
			comboBox_stripSteelGrade.Items.Add("T95-1");
			comboBox_stripSteelGrade.Items.Add("T95-2");
			comboBox_stripSteelGrade.Items.Add("P110");
			comboBox_stripSteelGrade.Items.Add("Q125-1");
			comboBox_stripSteelGrade.Items.Add("Q125-2");
			comboBox_stripSteelGrade.Items.Add("Q125-3");
			comboBox_stripSteelGrade.Items.Add("Q125-4");
			comboBox_stripSteelGrade.Items.Add("Q135");
			comboBox_stripSteelGrade.Items.Add("Д");
			comboBox_stripSteelGrade.Items.Add("К");
			comboBox_stripSteelGrade.Items.Add("Е");
			comboBox_stripSteelGrade.Items.Add("Л");
			comboBox_stripSteelGrade.Items.Add("М");
			comboBox_stripSteelGrade.Items.Add("Р");
			comboBox_stripSteelGrade.Items.Add("Т");
			comboBox_stripSteelGrade.Items.Add("L175 or A25");
			comboBox_stripSteelGrade.Items.Add("L210 or A");
			comboBox_stripSteelGrade.Items.Add("L245 or B");
			comboBox_stripSteelGrade.Items.Add("L290 or X42");
			comboBox_stripSteelGrade.Items.Add("L320 or X46");
			comboBox_stripSteelGrade.Items.Add("L360 or X52");
			comboBox_stripSteelGrade.Items.Add("L390 or X56");
			comboBox_stripSteelGrade.Items.Add("L415 or X60");
			comboBox_stripSteelGrade.Items.Add("L450 or X65");
			comboBox_stripSteelGrade.Items.Add("L486 or X70");
			comboBox_stripSteelGrade.Items.Add("L245N or BN");
			comboBox_stripSteelGrade.Items.Add("L290N or X42N");
			comboBox_stripSteelGrade.Items.Add("L320N or X46N");
			comboBox_stripSteelGrade.Items.Add("L360N or X52N");
			comboBox_stripSteelGrade.Items.Add("L390N or X56N");
			comboBox_stripSteelGrade.Items.Add("L415N or X60N");
			comboBox_stripSteelGrade.Items.Add("L245Q or BQ");
			comboBox_stripSteelGrade.Items.Add("L290Q or X42Q");
			comboBox_stripSteelGrade.Items.Add("L320Q or X46Q");
			comboBox_stripSteelGrade.Items.Add("L360Q or X52Q");
			comboBox_stripSteelGrade.Items.Add("L390Q or X56Q");
			comboBox_stripSteelGrade.Items.Add("L415Q or X60Q");
			#endregion			

			#region dictionaryComboBoxTaskStatus add item
			dictionaryComboBoxTaskStatus.Clear();
			dictionaryComboBoxTaskStatus.Add("createdUnBinded", "1");
			dictionaryComboBoxTaskStatus.Add("createdBinded", "2");
			dictionaryComboBoxTaskStatus.Add("started", "3");
			dictionaryComboBoxTaskStatus.Add("finished", "4");			
			#endregion
		}

		#region General\Task\Recipe dataGrid display
		public void RefreshPageTaskList(DataTable dataTable)
		{
			try
			{
				if (dataTable != null)
				{
					if (dataTable.TableName == TASK_INFO.tableName)
					{
						if (dataTable.Rows.Count > 0)
						{
							if (generalOrEditTask == "generalTask")
							{
								Dispatcher.Invoke(new Action(() =>
								{
									generalNaturalTasks.Clear();
								}
								));
								//General显示正常的订单
								DataTable naturalTable = new DataTable();
								DataRow[] dataRows = dataTable.Select(string.Format("{0}<>-9", TASK_INFO.fd_status), string.Format("{0} asc", TASK_INFO.fd_status));
								if (dataRows.Length > 0)
								{
									naturalTable = dataRows.CopyToDataTable<DataRow>();
								}
								generalNaturalTasks = TabletoDataGridTasks(naturalTable);
								dataGrid_GeneralTaskList.ItemsSource = generalNaturalTasks;
								dataGrid_GeneralTaskList.SelectedIndex = 0;
							}
							else if (generalOrEditTask == "taskTask")
							{
								//Task显示所有未完成订单
								editTasks = TabletoDataGridTasks(dataTable);
								dataGrid_TaskList.ItemsSource = editTasks;
								dataGrid_TaskList.SelectedIndex = 0;
							}
						}
					}
					//General display tasks that have not started and are being excuted
					else if (dataTable.TableName == TASK_INFO.generalTaskTableName)
					{
						if (dataTable.Rows.Count > 0)
						{
							Dispatcher.Invoke(new Action(() =>
							{
								generalNaturalTasks.Clear();
							}
									));
							generalNaturalTasks = TabletoDataGridTasks(dataTable);
							dataGrid_GeneralTaskList.ItemsSource = generalNaturalTasks;
							dataGrid_GeneralTaskList.SelectedIndex = 0;
							textBox_GeneralStripPage.Text = "1";
						}
					}
					//Task display all tasks
					else if (dataTable.TableName == TASK_INFO.taskTaskTableName)
					{
						if (dataTable.Rows.Count > 0)
						{
							editTasks = TabletoDataGridTasks(dataTable);
							dataGrid_TaskList.ItemsSource = editTasks;
							dataGrid_TaskList.SelectedIndex = 0;
							textBox_taskStripPage.Text = "1";
						}
						else
						{
							dataGrid_TaskList.ItemsSource = null;
							dataGrid_StripDetail.ItemsSource = null;
						}
					}
					//General display strips
					else if (dataTable.TableName == STRIP_INFO.generalStripTableName)
					{
						Dispatcher.Invoke(new Action(() =>
						{
							generalNaturalStrips.Clear();
						}
								  ));
						if (dataTable.Rows.Count > 0)
						{
							generalNaturalStrips = TabletoDataGridStrips(dataTable);
							dataGrid_GeneralStripList.ItemsSource = generalNaturalStrips;
						}
					}
					//Task display strips
					else if (dataTable.TableName == STRIP_INFO.taskStripTableName)
					{
						Dispatcher.Invoke(new Action(() =>
						{
							editStrips.Clear();
						}
								  ));
						if (dataTable.Rows.Count > 0)
						{
							editStrips = TabletoDataGridStrips(dataTable);
							dataGrid_StripDetail.ItemsSource = editStrips;
							DataRow[] unfinishedStripsRows = dataTable.Select(string.Format("{0} is not null", STRIP_INFO.fd_stripNo), string.Format("{0} desc", STRIP_INFO.fd_updateTime));
							if (unfinishedStripsRows.Length > 0)
							{
								editTaskStripTable = unfinishedStripsRows.CopyToDataTable();
							}
						}
						else
						{
							editTaskStripTable.Clear();
						}
					}
					//popupTask display tasks
					else if (dataTable.TableName == STRIP_INFO.popupTaskStripTableName)
					{						
						if (dataTable.Rows.Count > 0)
						{							
							dataGrid_TaskEditStrip.ItemsSource = dataTable.DefaultView;
						}
					}
					//display recipe information
					else if (dataTable.TableName == RECIPE_INFO.tableName)
					{
						//display task reicpe infromation
						if (recipeDetailMode == "RecipeDetail")
						{
							//refresh girde color

							ReflushTextBoxBackground();
							dataGrid_RecipeDetail.ItemsSource = dataTable.DefaultView;
							dataGrid_RecipeDetail.SelectedIndex = 0;
						}
						//display task bind recipe information
						else if (recipeDetailMode == "RecipeBind")
						{							
							dataGrid_BindRecipe.ItemsSource = dataTable.DefaultView;
							dataGrid_BindRecipe.SelectedIndex = 0;
						}
					}
					//display task batchsamplerule table data information
					else if (dataTable.TableName == BATCH_SAMPLE_RULE.tableName)
					{
						if (batchSampleRuleDetailMode == "BatchSampleRuleDetail")
						{
							//batchSampleRuleDetailDataTable = dataTable;
							//DataTable generalBatch = new DataTable();
							//if (dataTable.Rows.Count > 0)
							//{
							//	generalBatch = dataTable.DefaultView.ToTable(BATCH_SAMPLE_RULE.tableName, true, new string[] { BATCH_SAMPLE_RULE.fd_sampleNo, BATCH_SAMPLE_RULE.fd_sampleName, BATCH_SAMPLE_RULE.fd_updateTime });
							//}
							dataGrid_BatchRuleDetail.ItemsSource = dataTable.DefaultView;
							//dataGrid_BatchRuleDetail.SelectedIndex = 0;
						}
						else if (batchSampleRuleDetailMode == "BatchSampleRuleBind")
						{
							//DataTable bindBatchSampleRule = new DataTable();
							//if (dataTable.Rows.Count > 0)
							//{
							//	bindBatchSampleRule = dataTable.DefaultView.ToTable(BATCH_SAMPLE_RULE.tableName, true, new string[] { BATCH_SAMPLE_RULE.fd_sampleNo, BATCH_SAMPLE_RULE.fd_sampleName, BATCH_SAMPLE_RULE.fd_updateTime, BATCH_SAMPLE_RULE.fd_mtLength7, BATCH_SAMPLE_RULE.fd_mtLength6, BATCH_SAMPLE_RULE.fd_mtLength5, BATCH_SAMPLE_RULE.fd_mtLength4 });
							//}
							dataGrid_BindBatchSampleRule.ItemsSource = dataTable.DefaultView;
							dataGrid_BindBatchSampleRule.SelectedIndex = 0;
						}

					}
					//display task stripsamplerule table data information
					else if (dataTable.TableName == STRIP_SAMPLE_RULE.tableName)
					{
						if (stripSampleRuleDetailMode == "StripSampleRuleDetail")
						{
							//stripSampleRuleDetailDataTable = dataTable;
							//DataTable generalStrip = new DataTable();
							//if (dataTable.Rows.Count > 0)
							//{
							//	generalStrip = dataTable.DefaultView.ToTable(STRIP_SAMPLE_RULE.tableName, true, new string[] { STRIP_SAMPLE_RULE.fd_sampleNo, STRIP_SAMPLE_RULE.fd_sampleName, STRIP_SAMPLE_RULE.fd_updateTime });
							//}
							dataGrid_StripRuleDetail.ItemsSource = dataTable.DefaultView;
							//dataGrid_StripRuleDetail.SelectedIndex = 0;
						}
						else if (stripSampleRuleDetailMode == "StripSampleRuleBind")
						{
							//DataTable bindStripSampleRule = new DataTable();
							//if (dataTable.Rows.Count > 0)
							//{
							//	bindStripSampleRule = dataTable.DefaultView.ToTable(STRIP_SAMPLE_RULE.tableName, true, new string[] { STRIP_SAMPLE_RULE.fd_sampleNo, STRIP_SAMPLE_RULE.fd_sampleName, STRIP_SAMPLE_RULE.fd_updateTime, STRIP_SAMPLE_RULE.fd_mtMiddleLength, STRIP_SAMPLE_RULE.fd_mtFrontLength, STRIP_SAMPLE_RULE.fd_mtEndLength, STRIP_SAMPLE_RULE.fd_fltMiddleLength });
							//}
							dataGrid_BindStripSampleRule.ItemsSource = dataTable.DefaultView;
							dataGrid_BindStripSampleRule.SelectedIndex = 0;
						}
					}
					//display task productionstandard table data information
					else if (dataTable.TableName == PRODUCTION_STANDARD.tableName)
					{
						dataGrid_ProductionStandard.ItemsSource = dataTable.DefaultView;

						comboBox_ProStandard.Items.Clear();
						dictionaryProStandard.Clear();
						for (int i = 0; i < dataTable.Rows.Count; i++)
						{
							string standardCode = dataTable.Rows[i][PRODUCTION_STANDARD.fd_standardNo].ToString();
							string standardName = dataTable.Rows[i][PRODUCTION_STANDARD.fd_standardName].ToString();
							//PopTask的ProductionStandard参数编辑框							
							comboBox_ProStandard.Items.Add(standardName);
							//dictionaryProStandard add item							
							dictionaryProStandard.Add(standardName, standardCode);
						}
					}
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		public ObservableCollection<Tasks> TabletoDataGridTasks(DataTable dataTable)
		{
			try
			{
				ObservableCollection<Tasks> tasksCollection = new ObservableCollection<Tasks>();
				for (int i = 0; i < dataTable.Rows.Count; i++)
				{
					Tasks dataGridtask = new Tasks();
					dataGridtask.EventNo = dataTable.Rows[i][TASK_INFO.fd_eventNo].ToString();
					dataGridtask.TaskNo = dataTable.Rows[i][TASK_INFO.fd_taskNo].ToString();
					dataGridtask.PipeQuantityBatch = dataTable.Rows[i][TASK_INFO.fd_pipeQuantityBatch].ToString();
					dataGridtask.ProduceDestination = dataTable.Rows[i][TASK_INFO.fd_produceDestination].ToString();
					dataGridtask.Priority = dataTable.Rows[i][TASK_INFO.fd_priority].ToString();
					dataGridtask.BatchSampleRule = dataTable.Rows[i][TASK_INFO.fd_batchSampleRule].ToString();
					dataGridtask.StripSampleRule = dataTable.Rows[i][TASK_INFO.fd_stripSampleRule].ToString();
					dataGridtask.RecipeNo = dataTable.Rows[i][TASK_INFO.fd_recipeNo].ToString();
					dataGridtask.ProductionStandard = dataTable.Rows[i][TASK_INFO.fd_productionStandard].ToString();
					dataGridtask.PipeDurabilityClass = dataTable.Rows[i][TASK_INFO.fd_pipeDurabilityClass].ToString();
					dataGridtask.PipeSteelGrade = dataTable.Rows[i][TASK_INFO.fd_pipeSteelGrade].ToString();
					dataGridtask.PipeNominalMass = dataTable.Rows[i][TASK_INFO.fd_pipeNominalMass].ToString();
					dataGridtask.PipeNominalLength = dataTable.Rows[i][TASK_INFO.fd_pipeNominalLength].ToString();
					dataGridtask.PipeMaxLength = dataTable.Rows[i][TASK_INFO.fd_pipeMaxLength].ToString();
					dataGridtask.PipeMinLength = dataTable.Rows[i][TASK_INFO.fd_pipeMinLength].ToString();
					dataGridtask.PipeNominalOd = dataTable.Rows[i][TASK_INFO.fd_pipeNominalOd].ToString();
					dataGridtask.PipeMaxOd = dataTable.Rows[i][TASK_INFO.fd_pipeMaxOd].ToString();
					dataGridtask.PipeMinOd = dataTable.Rows[i][TASK_INFO.fd_pipeMinOd].ToString();
					dataGridtask.PipeNominalThickness = dataTable.Rows[i][TASK_INFO.fd_pipeNominalThickness].ToString();
					dataGridtask.PipeMinThickness = dataTable.Rows[i][TASK_INFO.fd_pipeMinThickness].ToString();
					dataGridtask.InnerBeadIsremoving = dataTable.Rows[i][TASK_INFO.fd_innerBeadIsremoving].ToString();
					dataGridtask.InnerBeadHeight = dataTable.Rows[i][TASK_INFO.fd_innerBeadHeight].ToString();
					dataGridtask.InnerBeadDepth = dataTable.Rows[i][TASK_INFO.fd_innerBeadDepth].ToString();
					dataGridtask.OvalityUpLimit = dataTable.Rows[i][TASK_INFO.fd_ovalityUpLimit].ToString();
					dataGridtask.BodyStraightness = dataTable.Rows[i][TASK_INFO.fd_bodyStraightness].ToString();
					dataGridtask.EndStraightness = dataTable.Rows[i][TASK_INFO.fd_endStraightness].ToString();
					dataGridtask.Status = dataTable.Rows[i][TASK_INFO.fd_status].ToString();
					dataGridtask.UpdateTime = dataTable.Rows[i][TASK_INFO.fd_updateTime].ToString();

					Dispatcher.Invoke(new Action(() =>
					{
						tasksCollection.Add(dataGridtask);
					}
								));
				}
				return tasksCollection;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				return null;
			}

		}
		public ObservableCollection<Strips> TabletoDataGridStrips(DataTable dataTable)
		{
			try
			{
				ObservableCollection<Strips> stripsCollection = new ObservableCollection<Strips>();
				for (int i = 0; i < dataTable.Rows.Count; i++)
				{
					Strips dataGridstrip = new Strips();
					dataGridstrip.EventNo = dataTable.Rows[i][STRIP_INFO.fd_eventNo].ToString();
					dataGridstrip.StripNo = dataTable.Rows[i][STRIP_INFO.fd_stripNo].ToString();
					dataGridstrip.BatchNoA = dataTable.Rows[i][STRIP_INFO.fd_batchNoA].ToString();
					dataGridstrip.BatchNoB = dataTable.Rows[i][STRIP_INFO.fd_batchNoB].ToString();
					dataGridstrip.TaskNo = dataTable.Rows[i][STRIP_INFO.fd_taskNo].ToString();
					dataGridstrip.IsSpy = dataTable.Rows[i][STRIP_INFO.fd_isSpy].ToString();
					dataGridstrip.IsEx = dataTable.Rows[i][STRIP_INFO.fd_isEx].ToString();
					dataGridstrip.StripDurabilityClass = dataTable.Rows[i][STRIP_INFO.fd_stripDurabilityClass].ToString();
					dataGridstrip.StripSteelGrade = dataTable.Rows[i][STRIP_INFO.fd_stripSteelGrade].ToString();
					dataGridstrip.StripHeat = dataTable.Rows[i][STRIP_INFO.fd_stripHeat].ToString();
					dataGridstrip.StripThk = dataTable.Rows[i][STRIP_INFO.fd_stripThk].ToString();
					dataGridstrip.StripWidth = dataTable.Rows[i][STRIP_INFO.fd_stripWidth].ToString();
					dataGridstrip.StripWeight = dataTable.Rows[i][STRIP_INFO.fd_stripWeight].ToString();
					dataGridstrip.BurrDirection = dataTable.Rows[i][STRIP_INFO.fd_burrDirection].ToString();
					dataGridstrip.Status = dataTable.Rows[i][STRIP_INFO.fd_status].ToString();
					dataGridstrip.UpdateTime = dataTable.Rows[i][STRIP_INFO.fd_updateTime].ToString();

					Dispatcher.Invoke(new Action(() =>
					{
						stripsCollection.Add(dataGridstrip);
					}
								));
				}
				return stripsCollection;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				return null;
			}
		}
		#endregion

		#region Task-General Handle
		/// <summary>
		/// refresh Task-General Task table data
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_GeneralFresh_Click(object sender, RoutedEventArgs e)
		{
			generalOrEditTask = "generalTask";
			client.SendMessage(Identity.definedCommand, Identity.select_GeneralTaskByIndex, ((generalTask_Index - 1) * generalTask_Pagenum) + ";" + generalTask_Index * generalTask_Pagenum);
		}
		/// <summary>
		/// Task-General Task table data page up
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_UpPage_generalTask_Click(object sender, RoutedEventArgs e)
		{
			if (generalTask_Index>1)
			{
				generalTask_Index--;
				generalOrEditTask = "generalTask";
				taskTaskMode = "GeneralTaskDetail";
				client.SendMessage(Identity.definedCommand, Identity.select_GeneralTaskByIndex, ((generalTask_Index - 1) * generalTask_Pagenum) + ";" + generalTask_Index * generalTask_Pagenum);
			}
			
		}
		/// <summary>
		/// Task-General Task table data page down
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_DownPage_generalTask_Click(object sender, RoutedEventArgs e)
		{
			if (Convert.ToInt32(textBox_GeneralTaskPage.Text) < Convert.ToInt32(textBox_GeneralTaskTotalPages.Text))
			{
				generalTask_Index++;
				textBox_GeneralTaskPage.Text = generalTask_Index.ToString();
				taskTaskMode = "GeneralTaskDetail";
				client.SendMessage(Identity.definedCommand, Identity.select_GeneralTaskByIndex, ((generalTask_Index - 1) * generalTask_Pagenum) + ";" + generalTask_Index * generalTask_Pagenum);
			}
		}
		/// <summary>
		///Task-General Strip table data page up
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>		
		private void btn_UpPage_generalStrip_Click(object sender, RoutedEventArgs e)
		{
			if (generalStrip_Index > 1)
			{
				generalStrip_Index--;
				textBox_GeneralStripPage.Text = generalStrip_Index.ToString();
				generalOrEditStrip = "generalStrip";
				client.SendMessage(Identity.definedCommand, Identity.select_STRIP_INFOByTaskNo, generaStripTaskNo + ";" + ((generalStrip_Index - 1) * generalStrip_Pagenum) + ";" + generalStrip_Index * generalStrip_Pagenum);
			}
			
		}
		/// <summary>
		/// Task-General Strip table data page down
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_DownPage_generalStrip_Click(object sender, RoutedEventArgs e)
		{
			if (generalStrip_index_isChange && Convert.ToInt32(textBox_GeneralStripPage.Text) < Convert.ToInt32(textBox_GeneralStripTotalPages.Text))
			{
				generalStrip_Index++;
				textBox_GeneralStripPage.Text = generalStrip_Index.ToString();
				generalOrEditStrip = "generalStrip";
				client.SendMessage(Identity.definedCommand, Identity.select_STRIP_INFOByTaskNo, generaStripTaskNo + ";" + ((generalStrip_Index - 1) * generalStrip_Pagenum) + ";" + generalStrip_Index * generalStrip_Pagenum);
			}
		}
		#endregion

		#region Task-Task Handle		
		/// <summary>
		///Task-Task Task table uncheck row information
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_TaskList_MouseDown(object sender, MouseButtonEventArgs e)
		{
			dataGrid_TaskList.SelectedItem = null;
		}
		/// <summary>
		/// refresh Task-Task Task table data
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_TaskRefrash_Click(object sender, RoutedEventArgs e)
		{
			generalOrEditTask = "taskTask";			
			client.SendMessage(Identity.definedCommand, Identity.selectTaskByParameters, taskPageSql + ";"+((taskTask_Index - 1) * taskTask_Pagenum) + ";" + taskTask_Index * taskTask_Pagenum);
		}
		/// <summary>
		/// Task-Task Task table page up
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_UpPage_taskTask_Click(object sender, RoutedEventArgs e)
		{
			if (taskTask_Index > 1)
			{
				taskTask_Index--;
				textBox_taskTaskPage.Text = taskTask_Index.ToString();
				if (taskPageSql == "")
				{
					taskPageSql= string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} order by {1} desc,{2} desc) a)",
				  TASK_INFO.tableName, TASK_INFO.fd_status, TASK_INFO.fd_updateTime);
				}
				taskTaskMode = "TaskTaskDetail";
				client.SendMessage(Identity.definedCommand, Identity.selectTaskByParameters, taskPageSql + ";" + ((taskTask_Index - 1) * taskTask_Pagenum) + ";" + taskTask_Index * taskTask_Pagenum);
			}			
		}
		/// <summary>
		/// Task-Task Task table page down
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_DownPage_taskTask_Click(object sender, RoutedEventArgs e)
		{
			if (taskTask_index_isChange && Convert.ToInt32(textBox_taskTaskPage.Text) < Convert.ToInt32(textBox_taskTaskTotalPages.Text))
			{
				taskTask_Index++;
				textBox_taskTaskPage.Text = taskTask_Index.ToString();
				if (taskPageSql == "")
				{
					taskPageSql = string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} order by {1} desc,{2} desc) a)",
				  TASK_INFO.tableName, TASK_INFO.fd_status, TASK_INFO.fd_updateTime);
				}
				taskTaskMode = "TaskTaskDetail";
				client.SendMessage(Identity.definedCommand, Identity.selectTaskByParameters, taskPageSql + ";" + ((taskTask_Index - 1) * taskTask_Pagenum) + ";" + taskTask_Index * taskTask_Pagenum);
			}
		}
		/// <summary>
		/// fuzzy query task table data
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_TaskSelect_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				string selectStartTime = Convert.ToString(datePicker_StartTime.SelectedDate?.ToString(Formats.GetShortFormat()));
				string selectendTime = Convert.ToString(datePicker_EndTime.SelectedDate?.ToString(Formats.GetShortFormat()));
				string Starttime = Convert.ToString(datePicker_StartTime.SelectedDate?.ToString(Formats.GetShortFormat())) + " "
							  + Convert.ToString(dateTimePickerstarttime.Value.ToString(Formats.GetTimeFormat()));  //查询开始时间
				string Endtime = Convert.ToString(datePicker_EndTime.SelectedDate?.ToString(Formats.GetShortFormat())) + " "
							   + Convert.ToString(dateTimePickerendtime.Value.ToString(Formats.GetTimeFormat()));  //查询结束时间
				string pipeMinOD = textBox_InputPipeMinOd.Text.ToString();
				string pipeMaxOD = textBox_InputPipeMaxOd.Text.ToString();
				string pipeMinTHK = textBox_InputPipeMinThickeness.Text.ToString();
				string pipeMaxTHK = textBox_InputPipeMaxThickeness.Text.ToString();
				string taskNo= textBox_InputTaskNo.Text.ToString();
				string taskStatus = "";
				if (comboBox_TaskTaskTaskStatus.SelectedIndex!= 0)
				{
                    //taskStatus = dictionaryComboBoxTaskStatus[comboBox_TaskTaskTaskStatus.Text.ToString()];
                    taskStatus = comboBox_TaskTaskTaskStatus.SelectedIndex.ToString();

                }
				
				string strsql = string.Format("select * from (select ROWNUM rn, d.* from (select * from {0} where 1=1", TASK_INFO.tableName);
				if (taskNo != "")
				{
					strsql += string.Format(" and {0} like '%{1}%'", TASK_INFO.fd_taskNo, taskNo);
				}

				if (taskStatus != "")
				{
					strsql += string.Format(" and {0}='{1}'", TASK_INFO.fd_status, taskStatus);
				}

				if (pipeMinTHK != "" && pipeMaxTHK != "")
				{
					strsql += string.Format(" and {0} >=", TASK_INFO.fd_pipeMinThickness) + pipeMinTHK + string.Format(" and {0}<=", TASK_INFO.fd_pipeNominalThickness) + pipeMaxTHK;
				}
				else if (pipeMinTHK == "" && pipeMaxTHK != "")
				{
					strsql += string.Format(" and {0}<=", TASK_INFO.fd_pipeNominalThickness) + pipeMaxTHK;
				}
				else if (pipeMinTHK != "" && pipeMaxTHK == "")
				{
					strsql += string.Format(" and {0} >=", TASK_INFO.fd_pipeMinThickness) + pipeMinTHK;
				}

				if (pipeMinOD != "" && pipeMaxOD != "")
				{
					strsql += string.Format(" and {0} >='", TASK_INFO.fd_pipeMinOd) + pipeMinOD + string.Format("' and {0}<='", TASK_INFO.fd_pipeMaxOd) + pipeMaxOD+"'";
				}
				else if (pipeMinOD == "" && pipeMaxOD != "")
				{
					strsql += string.Format(" and {0}<='", TASK_INFO.fd_pipeMaxOd) + pipeMaxOD+"'";
				}
				else if (pipeMinOD != "" && pipeMaxOD == "")
				{
					strsql += string.Format(" and {0} >='", TASK_INFO.fd_pipeMinOd) + pipeMinOD+"'";
				}

				if (selectStartTime != null && selectendTime == null)
				{
					strsql += string.Format(" and {0} >='", TASK_INFO.fd_updateTime) + Starttime + string.Format("' and {0}<='", TASK_INFO.fd_updateTime) + selectStartTime + " 23:59:59'"; 
				}
				else if (selectStartTime == null && selectendTime != null)
				{
					strsql += string.Format(" and {0} >='", TASK_INFO.fd_updateTime) + selectendTime + " 00:00:00" + string.Format("' and {0}<='", TASK_INFO.fd_updateTime) + Endtime + "'";
				}
				else if (selectStartTime != null && selectendTime != null)
				{
					strsql += string.Format(" and {0} >='", TASK_INFO.fd_updateTime) + Starttime + string.Format("' and {0}<='", TASK_INFO.fd_updateTime) + Endtime + "'";
				}
				//else if (selectStartTime == null && selectendTime == null)
				//{
				//	string starttime = DateTime.Now.Date.ToString(Formats.GetDateFormat());
				//	string endtime = DateTime.Now.ToString(Formats.GetDateFormat());
				//	strsql += string.Format(" and {0}>='", TASK_INFO.fd_updateTime) + starttime + string.Format("' and {0}<='", TASK_INFO.fd_updateTime) + endtime + "'";
				//}
				strsql += string.Format(" order by {0} desc,{1} desc) d)", TASK_INFO.fd_status, TASK_INFO.fd_updateTime);
				taskPageSql = strsql;
				textBox_taskTaskPage.Text = taskTask_Index.ToString();
				client.SendMessage(Identity.definedCommand, Identity.selectTaskByParameters, taskPageSql + ";0;20");
				LogHelper.WriteLog("btn_TaskSelect_Click");
				taskTask_Index = 1;
				textBox_taskTaskPage.Text = taskTask_Index.ToString();
				//taskSelectByTaskNo = "selectTaskByTaskNo";
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_TaskSelect_Click", ex);
			}
						
		}
		/// <summary>
		/// New one Task
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_NewTask_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				Popup_Task.IsOpen = true;
				textBox_TaskNo.IsEnabled = true;
				scrollViewer_PopupTask.IsEnabled = true;
				btn_TaskAddStrip.IsEnabled = false;
				btn_TaskEditStrip.IsEnabled = false;
				btn_TaskDeleteStrip.IsEnabled = false;
				grid_PopupTask_TaskParameters.IsEnabled = true;
				if (dataGrid_TaskList.SelectedItem != null)
				{
					var task = dataGrid_TaskList.SelectedItem as Tasks;
					textBox_TaskNo.Text = "";
					textBox_PipeQuaBatch.Text = task.PipeQuantityBatch;
					textBox_ProDestination.Text = task.ProduceDestination;
					textBox_Priority.Text = task.Priority;
					textBox_BatchSamRule.Text = task.BatchSampleRule;
					textBox_StripSamRule.Text = task.StripSampleRule;
					textBox_RecipeNo.Text = task.RecipeNo;

					var proStandard = dictionaryProStandard.FirstOrDefault(q => q.Value == task.ProductionStandard).Key;
					if (proStandard != null)
					{
						comboBox_ProStandard.Text = proStandard;
					}
					else
                    {
						comboBox_ProStandard.Text = "";

					}

					var pipeDUrCLass = dictionaryDurClassAndSteelGrade.FirstOrDefault(q => q.Value == task.PipeDurabilityClass).Key;
					if (pipeDUrCLass != null)
					{
						comboBox_ProStandard.Text = pipeDUrCLass;
					}
					else
					{
						comboBox_ProStandard.Text = "";

					}

					var pipeSteelGrade = dictionaryDurClassAndSteelGrade.FirstOrDefault(q => q.Value == task.PipeSteelGrade).Key;
					if (pipeSteelGrade != null)
					{
						comboBox_PipeSteelGrade.Text = pipeSteelGrade;
					}
					else
					{
						comboBox_PipeSteelGrade.Text = "";

					}

					textBox_PipeNomMass.Text = task.PipeNominalMass;
					textBox_PipeNomLength.Text = task.PipeNominalLength;
					textBox_PipeMaxLength.Text = task.PipeMaxLength;
					textBox_PipeMinLength.Text = task.PipeMinLength;
					textBox_PipeNomOd.Text = task.PipeNominalOd;
					textBox_PipeMaxOd.Text = task.PipeMaxOd;
					textBox_PipeMinOd.Text = task.PipeMinOd;
					textBox_PipeNomThickness.Text = task.PipeNominalThickness;
					textBox_PipeMinThickness.Text = task.PipeMinThickness;
					textBox_InnerBeadIsremoving.Text = task.InnerBeadIsremoving;
					textBox_InnerBeadHeight.Text = task.InnerBeadHeight;
					textBox_InnerBeadDepth.Text = task.InnerBeadDepth;
					textBox_OvalityUpLimit.Text = task.OvalityUpLimit;
					textBox_BodyStraightness.Text = task.BodyStraightness;
					textBox_EndStraightness.Text = task.EndStraightness;
				}
				else
				{
					textBox_TaskNo.Text = "";
					textBox_PipeQuaBatch.Text = "";
					textBox_ProDestination.Text = "";
					textBox_Priority.Text = "";
					textBox_BatchSamRule.Text = "";
					textBox_StripSamRule.Text = "";
					textBox_RecipeNo.Text = "";
					comboBox_ProStandard.Text = "";
					comboBox_PipeDurClass.Text = "";
					comboBox_PipeSteelGrade.Text = "";
					textBox_PipeNomMass.Text = "";
					textBox_PipeNomLength.Text = "";
					textBox_PipeMaxLength.Text = "";
					textBox_PipeMinLength.Text = "";
					textBox_PipeNomOd.Text = "";
					textBox_PipeMaxOd.Text = "";
					textBox_PipeMinOd.Text = "";
					textBox_PipeNomThickness.Text = "";
					textBox_PipeMinThickness.Text = "";
					textBox_InnerBeadIsremoving.Text = "";
					textBox_InnerBeadHeight.Text = "";
					textBox_InnerBeadDepth.Text = "";
					textBox_OvalityUpLimit.Text = "";
					textBox_BodyStraightness.Text = "";
					textBox_EndStraightness.Text = "";
				}
				dataGrid_TaskEditStrip.ItemsSource = null;
				btnSaveOrder = "New";
				//设置Popup的高度		
				DependencyObject parent = Popup_Task.Child;
				do
				{
					parent = VisualTreeHelper.GetParent(parent);
					if (parent != null && parent.ToString() == "System.Windows.Controls.Primitives.PopupRoot")
					{
						var element = parent as FrameworkElement;
						element.Height = 640;
						break;
					}
				}
				while (parent != null);				
				LogHelper.WriteLog("btn_NewTask_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_NewTask_Click", ex);
			}
		}
		/// <summary>
		/// Edit Task
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>		
		private void btn_TaskEdit_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (dataGrid_TaskList.SelectedItem == null)
				{
					MessageBox.Show("please select a unstart task");
					return;
				}
				var task = dataGrid_TaskList.SelectedItem as Tasks;
				if (task != null)
				{
					string taskStatus = task.Status;
					Popup_Task.IsOpen = true;
					btn_TaskAddStrip.IsEnabled = true;
					btn_TaskEditStrip.IsEnabled = true;
					btn_TaskDeleteStrip.IsEnabled = true;
					btnSaveOrder = "Edit";
					generalOrEditStrip = "popuptaskStrip";
					taskEditStrip_Index = 1;
					textBox_TaskEditStripCurrentPage.Text = taskEditStrip_Index.ToString();
					textBox_TaskEditStripTotalPages.Text = textBox_taskStripTotalPages.Text;
					//edit_status = "edit_font";
					popupTaskStripTaskNo = task.TaskNo;
					textBox_TaskNo.IsEnabled = false;
					textBox_TaskNo.Text = task.TaskNo;
					textBox_PipeQuaBatch.Text = task.PipeQuantityBatch;
					textBox_ProDestination.Text = task.ProduceDestination;
					textBox_Priority.Text = task.Priority;
					textBox_BatchSamRule.Text = task.BatchSampleRule;
					textBox_StripSamRule.Text = task.StripSampleRule;
					textBox_RecipeNo.Text = task.RecipeNo;

					var proStandard = dictionaryProStandard.FirstOrDefault(q => q.Value == task.ProductionStandard).Key;
					if (proStandard != null)
					{
						comboBox_ProStandard.Text = proStandard;
					}
					else
					{
						comboBox_ProStandard.Text = "";

					}

					var pipeDUrCLass = dictionaryDurClassAndSteelGrade.FirstOrDefault(q => q.Value == task.PipeDurabilityClass).Key;
					if (pipeDUrCLass != null)
					{
						comboBox_ProStandard.Text = pipeDUrCLass;
					}
					else
					{
						comboBox_ProStandard.Text = "";

					}

					var pipeSteelGrade = dictionaryDurClassAndSteelGrade.FirstOrDefault(q => q.Value == task.PipeSteelGrade).Key;
					if (pipeSteelGrade != null)
					{
						comboBox_PipeSteelGrade.Text = pipeSteelGrade;
					}
					else
					{
						comboBox_PipeSteelGrade.Text = "";

					}

					textBox_PipeNomMass.Text = task.PipeNominalMass;
					textBox_PipeNomLength.Text = task.PipeNominalLength;
					textBox_PipeMaxLength.Text = task.PipeMaxLength;
					textBox_PipeMinLength.Text = task.PipeMinLength;
					textBox_PipeNomOd.Text = task.PipeNominalOd;
					textBox_PipeMaxOd.Text = task.PipeMaxOd;
					textBox_PipeMinOd.Text = task.PipeMinOd;
					textBox_PipeNomThickness.Text = task.PipeNominalThickness;
					textBox_PipeMinThickness.Text = task.PipeMinThickness;
					textBox_InnerBeadIsremoving.Text = task.InnerBeadIsremoving;
					textBox_InnerBeadHeight.Text = task.InnerBeadHeight;
					textBox_InnerBeadDepth.Text = task.InnerBeadDepth;
					textBox_OvalityUpLimit.Text = task.OvalityUpLimit;
					textBox_BodyStraightness.Text = task.BodyStraightness;
					textBox_EndStraightness.Text = task.EndStraightness;

					if (taskStatus == "1" || taskStatus == "2")
					{
                        grid_PopupTask_TaskParameters.IsEnabled = true;
                        scrollViewer_PopupTask.IsEnabled = true;
                    }
					else
					{
                        grid_PopupTask_TaskParameters.IsEnabled = false;
                    }
					dataGrid_TaskEditStrip.ItemsSource = editTaskStripTable.DefaultView;
					//设置Popup的高度		
					DependencyObject parent = Popup_Task.Child;
					do
					{
						parent = VisualTreeHelper.GetParent(parent);
						if (parent != null && parent.ToString() == "System.Windows.Controls.Primitives.PopupRoot")
						{
							var element = parent as FrameworkElement;
							element.Height = 640;
							break;
						}
					}
					while (parent != null);
				}
				LogHelper.WriteLog("menuItem_EditTask_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("menuItem_EditTask_Click", ex);
			}
		}
		/// <summary>
		/// Save Task
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_SaveTask_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				string taskStatus = "";




				//除了recipeNo, batchSampleRule, stripSampleRule其他输入框不能为空 
				// 2022-03-29  新增 Pipe_durability_class 可以为空
				if (textBox_TaskNo.Text.ToString() == "" || textBox_PipeQuaBatch.Text == "" || textBox_ProDestination.Text.ToString() == "" || textBox_Priority.Text.ToString() == "" || comboBox_ProStandard.Text.ToString() == "" ||
					comboBox_PipeSteelGrade.Text.ToString() == "" || textBox_PipeNomMass.Text.ToString() == "" || textBox_PipeNomLength.Text.ToString() == "" ||
					textBox_PipeMaxLength.Text.ToString() == "" || textBox_PipeMinLength.Text.ToString() == "" || textBox_PipeNomOd.Text.ToString() == "" || textBox_PipeMaxOd.Text.ToString() == "" || textBox_PipeMinOd.Text.ToString() == "" ||
					textBox_PipeNomThickness.Text.ToString() == "" || textBox_PipeMinThickness.Text.ToString() == "" || textBox_InnerBeadIsremoving.Text.ToString() == "" || textBox_InnerBeadHeight.Text.ToString() == "" || textBox_InnerBeadDepth.Text.ToString() == "" ||
					textBox_OvalityUpLimit.Text.ToString() == "" || textBox_BodyStraightness.Text.ToString() == "" || textBox_EndStraightness.Text.ToString() == "")
				{
					MessageBox.Show("In addition to recipeNo, batchSampleRule, stripSampleRule,Pipe_durability_class, other parameters can not be empty.");
					return;
				}

				//if (textBox_TaskNo.Text.ToString() == "" || textBox_PipeQuaBatch.Text == "" || textBox_ProDestination.Text.ToString() == "" || textBox_Priority.Text.ToString() == "" || comboBox_ProStandard.Text.ToString() == "" ||
				//	textBox_PipeDurClass.Text.ToString() == "" || textBox_PipeSteelGrade.Text.ToString() == "" || textBox_PipeNomMass.Text.ToString() == "" || textBox_PipeNomLength.Text.ToString() == "" ||
				//	textBox_PipeMaxLength.Text.ToString() == "" || textBox_PipeMinLength.Text.ToString() == "" || textBox_PipeNomOd.Text.ToString() == "" || textBox_PipeMaxOd.Text.ToString() == "" || textBox_PipeMinOd.Text.ToString() == "" ||
				//	textBox_PipeNomThickness.Text.ToString() == "" || textBox_PipeMinThickness.Text.ToString() == "" || textBox_InnerBeadIsremoving.Text.ToString() == "" || textBox_InnerBeadHeight.Text.ToString() == "" || textBox_InnerBeadDepth.Text.ToString() == "" ||
				//	textBox_OvalityUpLimit.Text.ToString() == "" || textBox_BodyStraightness.Text.ToString() == "" || textBox_EndStraightness.Text.ToString() == "")
				//{
				//	MessageBox.Show("In addition to recipeNo, batchSampleRule, stripSampleRule, other parameters can not be empty.");
				//	return;
				//}
				//判断ProductionStandard是否存在
				if (!dictionaryProStandard.ContainsKey(comboBox_ProStandard.Text.ToString()))
				{
					MessageBox.Show("ProductionStandard does not exist, please select");
					return;
				}

				//判断PipeNomMass
				double pipe_Nominal_Mass = 0;
				if (!double.TryParse(textBox_PipeNomMass.Text.ToString(),out pipe_Nominal_Mass))
				{
					MessageBox.Show("Pipe Nominal Mass must be numeric, please re-enter");
					return;
				}
				//判断PipeNomMass
				double pipe_Nominal_Length = 0;
				if (!double.TryParse(textBox_PipeNomLength.Text.ToString(), out pipe_Nominal_Length))
				{
					MessageBox.Show("Pipe Nominal Lenght must be numeric, please re-enter");
					return;
				}
				//判断PipeNomMass
				double pipe_Max_Length = 0;
				if (!double.TryParse(textBox_PipeMaxLength.Text.ToString(), out pipe_Max_Length))
				{
					MessageBox.Show("Pipe Max Length must be numeric, please re-enter");
					return;
				}
				//判断PipeNomMass
				double pipe_Min_Length = 0;
				if (!double.TryParse(textBox_PipeMinLength.Text.ToString(), out pipe_Min_Length))
				{
					MessageBox.Show("Pipe Nominal Mass must be numeric, please re-enter");
					return;
				}
				//判断PipeNomMass
				double pipeNomOd = 0;
				if (!double.TryParse(textBox_PipeNomOd.Text.ToString(), out pipeNomOd))
				{
					MessageBox.Show("Pipe Nominal OD must be numeric, please re-enter");
					return;
				}
				//判断PipeNomMass
				double pipeMaxOD = 0;
				if (!double.TryParse(textBox_PipeMaxOd.Text.ToString(), out pipeMaxOD))
				{
					MessageBox.Show("Pipe Max OD must be numeric, please re-enter");
					return;
				}
				//判断PipeNomMass
				double pipeMinOD = 0;
				if (!double.TryParse(textBox_PipeMinOd.Text.ToString(), out pipeMinOD))
				{
					MessageBox.Show("Pipe Min OD must be numeric, please re-enter");
					return;
				}
				//判断PipeNomMass
				double pipeNomTHK = 0;
				if (!double.TryParse(textBox_PipeNomThickness.Text.ToString(), out pipeNomTHK))
				{
					MessageBox.Show("Pipe Nominal Thickness must be numeric, please re-enter");
					return;
				}
				//判断PipeNomMass
				double pipeMinTHK = 0;
				if (!double.TryParse(textBox_PipeMinThickness.Text.ToString(), out pipeMinTHK))
				{
					MessageBox.Show("Pipe Min Thickness must be numeric, please re-enter");
					return;
				}

				DataTable dataTableTask = new DataTable();
				dataTableTask.Columns.Add(TASK_INFO.fd_eventNo, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_taskNo, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_pipeQuantityBatch, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_produceDestination, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_priority, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_batchSampleRule, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_stripSampleRule, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_recipeNo, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_productionStandard, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_pipeDurabilityClass, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_pipeSteelGrade, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_pipeNominalMass, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_pipeNominalLength, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_pipeMaxLength, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_pipeMinLength, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_pipeNominalOd, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_pipeMaxOd, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_pipeMinOd, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_pipeNominalThickness, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_pipeMinThickness, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_innerBeadIsremoving, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_innerBeadHeight, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_innerBeadDepth, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_ovalityUpLimit, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_bodyStraightness, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_endStraightness, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_status, typeof(string));
				dataTableTask.Columns.Add(TASK_INFO.fd_updateTime, typeof(string));

				if (textBox_BatchSamRule.Text == "" || textBox_StripSamRule.Text == "" || textBox_RecipeNo.Text == "")
				{
					taskStatus = "1";
				}
				else
				{
					taskStatus = "2";
				}



				//var proStandard = dictionaryProStandard.FirstOrDefault(q => q.Value == task.ProductionStandard).Key;
				bool rs = dictionaryProStandard.TryGetValue(comboBox_ProStandard.Text,out string proStand);
				if(!rs)
                {
					MessageBox.Show("Production Standard is not exist!");
					return;

				}

				rs = dictionaryDurClassAndSteelGrade.TryGetValue(comboBox_PipeSteelGrade.Text, out string pipeSteelGrade);
				if (!rs)
				{
					MessageBox.Show("Pipe Steel Greade is not exist!");
					return;

				}

				rs = dictionaryDurClassAndSteelGrade.TryGetValue(comboBox_PipeDurClass.Text, out string pipeDurClass);
				if (!rs)
				{
					pipeDurClass = " ";

				}

				dataTableTask.Rows.Add(0, textBox_TaskNo.Text, textBox_PipeQuaBatch.Text, textBox_ProDestination.Text, textBox_Priority.Text, textBox_BatchSamRule.Text, textBox_StripSamRule.Text,
					textBox_RecipeNo.Text, proStand, pipeDurClass, pipeSteelGrade, textBox_PipeNomMass.Text,
					textBox_PipeNomLength.Text, textBox_PipeMaxLength.Text, textBox_PipeMinLength.Text, textBox_PipeNomOd.Text, textBox_PipeMaxOd.Text, textBox_PipeMinOd.Text,
					textBox_PipeNomThickness.Text, textBox_PipeMinThickness.Text, textBox_InnerBeadIsremoving.Text, textBox_InnerBeadHeight.Text, textBox_InnerBeadDepth.Text, textBox_OvalityUpLimit.Text,
					textBox_BodyStraightness.Text, textBox_EndStraightness.Text, taskStatus, DateTime.Now.ToString(Formats.GetDateFormat()));
				string jsonTaskInfo = JsonHelper.SerializeObject(dataTableTask);
								
				if (dataTableTask != null && dataTableTask.Rows.Count > 0)
				{
					if (btnSaveOrder == "New")
					{
						generalOrEditTask = "allTask";
						generalOrEditStrip = "taskStrip";
						client.SendMessage(Identity.definedCommand, Identity.insert_TASK, jsonTaskInfo + ";" + USER_TABLE.user_No);
					}
					if (btnSaveOrder == "Edit")
					{
						generalOrEditTask = "allTask";
						generalOrEditStrip = "taskStrip";
						client.SendMessage(Identity.definedCommand, Identity.updateTaskByTaskNo, jsonTaskInfo + ";" + USER_TABLE.user_No);
					}
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		/// <summary>
		/// Delete Task
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>				
		private void btn_TaskDelete_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				generalOrEditTask = "allTask";
				var task = dataGrid_TaskList.SelectedItem as Tasks;
				if (task.Status == "3")
				{
					MessageBox.Show("The task is loading and cannot be deleted.");
					return;
				}
				else if (task.Status == "4")
				{
					MessageBox.Show("The task is finished and cannot be deleted.");
					return;
				}
				if (task != null)
				{
					if (MessageBox.Show("Are you sure you want to delete the task?", "DELETE", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
					{
						string taskNo = task.TaskNo;
						client.SendMessage("Defined", Identity.deleteUnloadingTask, taskNo + ";" + USER_TABLE.user_No + ";" + ((taskTask_Index - 1) * taskTask_Pagenum) + ";" + taskTask_Index * taskTask_Pagenum);
					}
				}
				LogHelper.WriteLog("menuItem_DeleteTask_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("menuItem_DeleteTask_Click", ex);
			}
		}
		/// <summary>
		/// Close Popup_Task
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_CloseTask_Click(object sender, RoutedEventArgs e)
		{
			Popup_Task.IsOpen = false;
		}
		#region Task-Task Strip table handle		
		/// <summary>
		/// Task-Task Strip table data page up
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_UpPage_taskStrip_Click(object sender, RoutedEventArgs e)
		{
			if (taskStrip_Index > 1)
			{
				taskStrip_Index--;
				textBox_taskStripPage.Text = taskStrip_Index.ToString();
			}
			generalOrEditStrip = "taskStrip";
			client.SendMessage(Identity.definedCommand, Identity.select_STRIP_INFOByTaskNo, taskStripTaskNo + ";" + ((taskStrip_Index - 1) * taskStrip_Pagenum) + ";" + taskStrip_Index * taskStrip_Pagenum);
		}
		/// <summary>
		/// Task-Task Strip table data page down
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_DownPage_taskStrip_Click(object sender, RoutedEventArgs e)
		{
			if (taskStrip_index_isChange && Convert.ToInt32(textBox_taskStripPage.Text) < Convert.ToInt32(textBox_taskStripTotalPages.Text))
			{
				taskStrip_Index++;
				textBox_taskStripPage.Text = taskStrip_Index.ToString();
				generalOrEditStrip = "taskStrip";
				client.SendMessage(Identity.definedCommand, Identity.select_STRIP_INFOByTaskNo, taskStripTaskNo + ";" + ((taskStrip_Index - 1) * taskStrip_Pagenum) + ";" + taskStrip_Index * taskStrip_Pagenum);
			}
		}
		/// <summary>
		/// Task-Task Popuptask Strip table uncheck row information
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_TaskEditStrip_MouseDown(object sender, MouseButtonEventArgs e)
		{
			dataGrid_TaskEditStrip.SelectedItem = null;
		}
		/// <summary>
		///  Task-Task Popuptask Strip table page up
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_TaskEditStrip_PageUp_Click(object sender, RoutedEventArgs e)
		{
			if (taskEditStrip_Index > 1)
			{
				taskEditStrip_Index--;
				textBox_TaskEditStripCurrentPage.Text = taskEditStrip_Index.ToString();
			}
			generalOrEditStrip = "popupTaskStrip";
			client.SendMessage(Identity.definedCommand, Identity.select_STRIP_INFOByTaskNo, popupTaskStripTaskNo + ";" + ((taskEditStrip_Index - 1) * taskEditStrip_Pagenum) + ";" + taskEditStrip_Index * taskEditStrip_Pagenum);
		}
		/// <summary>
		/// Task-Task Popuptask Strip table page down
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_TaskEditStrip_PageDown_Click(object sender, RoutedEventArgs e)
		{
			if (taskEditStrip_index_isChange && Convert.ToInt32(textBox_TaskEditStripCurrentPage.Text) < Convert.ToInt32(textBox_TaskEditStripTotalPages.Text))
			{
				taskEditStrip_Index++;
				textBox_TaskEditStripCurrentPage.Text = taskEditStrip_Index.ToString();
				generalOrEditStrip = "popupTaskStrip";
				client.SendMessage(Identity.definedCommand, Identity.select_STRIP_INFOByTaskNo, popupTaskStripTaskNo + ";" + ((taskEditStrip_Index - 1) * taskEditStrip_Pagenum) + ";" + taskEditStrip_Index * taskEditStrip_Pagenum);
			}
		}
		/// <summary>
		/// Task-Task Popuptask Add Strip
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_TaskAddStrip_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				Popup_Strip.IsOpen = true;
				if (dataGrid_TaskEditStrip.SelectedItem != null)
				{
					textBox_stripNo.IsEnabled = true;
					var strip = dataGrid_TaskEditStrip.SelectedItem as DataRowView;
					if (strip != null)
					{
						string taskNo = strip[STRIP_INFO.fd_taskNo].ToString();
						textBox_taskNo.Text = taskNo;
						textBox_Status.Text = "0";
						textBox_stripNo.Text = "";
						textBox_batchNoA.Text = strip[STRIP_INFO.fd_batchNoA].ToString();
						textBox_batchNoB.Text = strip[STRIP_INFO.fd_batchNoB].ToString();
						comboBox_isSpy.Text = strip[STRIP_INFO.fd_isSpy].ToString();
						comboBox_isEx.Text = strip[STRIP_INFO.fd_isEx].ToString();
						comboBox_stripDurClass.Text = dictionaryDurClassAndSteelGrade.FirstOrDefault(q => q.Value == strip[STRIP_INFO.fd_stripDurabilityClass].ToString()).Key.ToString();
						comboBox_stripSteelGrade.Text = dictionaryDurClassAndSteelGrade.FirstOrDefault(q => q.Value == strip[STRIP_INFO.fd_stripSteelGrade].ToString()).Key.ToString();
						textBox_stripHeat.Text = strip[STRIP_INFO.fd_stripHeat].ToString();
						textBox_stripThk.Text = strip[STRIP_INFO.fd_stripThk].ToString();
						textBox_stripWidth.Text = strip[STRIP_INFO.fd_stripWidth].ToString();
						textBox_stripWeight.Text = strip[STRIP_INFO.fd_stripWeight].ToString();
						textBox_burrDirection.Text = strip[STRIP_INFO.fd_burrDirection].ToString();
					}
				}
				else
				{
					Popup_Strip.IsOpen = true;
					string taskNo = textBox_TaskNo.Text;
					textBox_taskNo.Text = taskNo;
					textBox_Status.Text = "0";
					textBox_stripNo.Text = "";
					textBox_batchNoA.Text = "";
					textBox_batchNoB.Text = "";
					comboBox_isSpy.Text = "";
					comboBox_isEx.Text = "";
					comboBox_stripDurClass.Text = "";
					comboBox_stripSteelGrade.Text = "";
					textBox_stripHeat.Text = "";
					textBox_stripThk.Text = "";
					textBox_stripWidth.Text = "";
					textBox_stripWeight.Text = "";
					textBox_burrDirection.Text = "";
				}
				btnSaveStrip = "New";
				LogHelper.WriteLog("menuItem_AddStrip_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("menuItem_AddStrip_Click", ex);
			}
		}
		/// <summary>
		/// Task-Task Popuptask  Edit Strip
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_TaskEditStrip_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				Popup_Strip.IsOpen = true;
				if (dataGrid_TaskEditStrip.SelectedItem != null)
				{
					var strip = dataGrid_TaskEditStrip.SelectedItem as DataRowView;
					if (strip != null)
					{
						if (strip[STRIP_INFO.fd_status].ToString() == "0" || strip[STRIP_INFO.fd_status].ToString() == "1")
						{
							string taskNo = strip[STRIP_INFO.fd_taskNo].ToString();
							textBox_taskNo.IsEnabled = false;
							textBox_stripNo.IsEnabled = false;
							textBox_taskNo.Text = taskNo;
							textBox_Status.Text = strip[STRIP_INFO.fd_status].ToString();
							textBox_stripNo.Text = strip[STRIP_INFO.fd_stripNo].ToString();
							textBox_batchNoA.Text = strip[STRIP_INFO.fd_batchNoA].ToString();
							textBox_batchNoB.Text = strip[STRIP_INFO.fd_batchNoB].ToString();
							comboBox_isSpy.Text = strip[STRIP_INFO.fd_isSpy].ToString();
							comboBox_isEx.Text = strip[STRIP_INFO.fd_isEx].ToString();
							comboBox_stripDurClass.Text = dictionaryDurClassAndSteelGrade.FirstOrDefault(q => q.Value == strip[STRIP_INFO.fd_stripDurabilityClass].ToString()).Key.ToString();
							comboBox_stripSteelGrade.Text = dictionaryDurClassAndSteelGrade.FirstOrDefault(q => q.Value == strip[STRIP_INFO.fd_stripSteelGrade].ToString()).Key.ToString();
							textBox_stripHeat.Text = strip[STRIP_INFO.fd_stripHeat].ToString();
							textBox_stripThk.Text = strip[STRIP_INFO.fd_stripThk].ToString();
							textBox_stripWidth.Text = strip[STRIP_INFO.fd_stripWidth].ToString();
							textBox_stripWeight.Text = strip[STRIP_INFO.fd_stripWeight].ToString();
							textBox_burrDirection.Text = strip[STRIP_INFO.fd_burrDirection].ToString();

							btnSaveStrip = "Edit";
						}
						else
						{
							MessageBox.Show("please select a unstart strip");
						}

					}
				}
				else
				{
					MessageBox.Show("please select a strip");
				}
				LogHelper.WriteLog("btn_TaskEditStrip_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_TaskEditStrip_Click", ex);
			}
		}
		/// <summary>
		/// Task-Task Popuptask Save strip
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_SaveSingleStrip_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (textBox_stripNo.Text.ToString() == "" || textBox_batchNoA.Text == "" || textBox_batchNoB.Text.ToString() == "" || textBox_taskNo.Text.ToString() == "" || comboBox_isSpy.Text.ToString() == "" ||
					comboBox_isEx.Text.ToString() == "" || comboBox_stripDurClass.Text.ToString() == "" || comboBox_stripSteelGrade.Text.ToString() == "" && textBox_stripHeat.Text.ToString() == "" ||
					textBox_stripThk.Text.ToString() == "" || textBox_stripWidth.Text.ToString() == "" || textBox_stripWeight.Text.ToString() == "" || textBox_burrDirection.Text.ToString() == "" || textBox_Status.Text.ToString() == ""
					)
				{
					MessageBox.Show("strip parameter cannot be empty.");
					return;
				}
				//判断comboBox_stripDurClass是否存在
				if (!dictionaryDurClassAndSteelGrade.ContainsKey(comboBox_stripDurClass.Text.ToString()))
				{
					MessageBox.Show("stripDurClass does not exist,please re-enter");
					return;
				}
				//comboBox_stripSteelGrade
				if (!dictionaryDurClassAndSteelGrade.ContainsKey(comboBox_stripSteelGrade.Text.ToString()))
				{
					MessageBox.Show("stripSteelGrade does not exist,please re-enter");
					return;
				}

				dataTableStripInfo = new DataTable();
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_eventNo, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_stripNo, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_batchNoA, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_batchNoB, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_taskNo, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_isSpy, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_isEx, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_stripDurabilityClass, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_stripSteelGrade, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_stripHeat, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_stripThk, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_stripWidth, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_stripWeight, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_burrDirection, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_status, typeof(string));
				dataTableStripInfo.Columns.Add(STRIP_INFO.fd_updateTime, typeof(string));
				dataTableStripInfo.Rows.Add(0, textBox_stripNo.Text, textBox_batchNoA.Text.ToString(), textBox_batchNoB.Text, textBox_taskNo.Text, comboBox_isSpy.Text, comboBox_isEx.Text, dictionaryDurClassAndSteelGrade[comboBox_stripDurClass.Text], dictionaryDurClassAndSteelGrade[comboBox_stripSteelGrade.Text], textBox_stripHeat.Text.ToString(), textBox_stripThk.Text, textBox_stripWidth.Text, textBox_stripWeight.Text, textBox_burrDirection.Text, textBox_Status.Text, DateTime.Now.ToString(Formats.GetDateFormat()));
				string jsonstripinfo = JsonHelper.SerializeObject(dataTableStripInfo);
				if (dataTableStripInfo != null && dataTableStripInfo.Rows.Count > 0)
				{
					if (btnSaveStrip == "New")
					{
						generalOrEditTask = "allTask";
						generalOrEditStrip = "taskStrip";
						client.SendMessage(Identity.definedCommand, Identity.insert_STRIP_INFO, jsonstripinfo + ";" + USER_TABLE.user_No);
					}
					else if (btnSaveStrip == "Edit")
					{
						generalOrEditTask = "allTask";
						generalOrEditStrip = "taskStrip";
						client.SendMessage(Identity.definedCommand, Identity.updateStripByStripNo, jsonstripinfo + ";" + USER_TABLE.user_No);
					}					
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		/// <summary>
		/// Task-Task Popuptask Delete strip
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_TaskDeleteStrip_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				var stripdrv = dataGrid_TaskEditStrip.SelectedItem as DataRowView;
				if (stripdrv != null)
				{
					string status = stripdrv[STRIP_INFO.fd_status].ToString();
					if (status != "")
					{
						if (status == "2")
						{
							MessageBox.Show("strip loading cannot be deleted.");
							return;
						}
						if (status == "3")
						{
							MessageBox.Show("strip is finished and cannot be deleted.");
							return;
						}
					}
					if (MessageBox.Show("Are you sure you want to delete the strip?", "DELETE", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
					{
						string stripNo = stripdrv[STRIP_INFO.fd_stripNo].ToString();
						client.SendMessage(Identity.definedCommand, Identity.deleteStripInfoByStrip_code, stripNo + ";" + USER_TABLE.user_No + ";" + ((taskEditStrip_Index - 1) * taskEditStrip_Pagenum) + ";" + taskEditStrip_Index * taskEditStrip_Pagenum);
					}
				}
				LogHelper.WriteLog("btn_TaskDeleteStrip_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_TaskDeleteStrip_Click", ex);
			}
		}		
		/// <summary>
		/// close popup strip
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_Strip_Close_Click(object sender, RoutedEventArgs e)
		{
			Popup_Strip.IsOpen = false;
		}
		#endregion
		#endregion

		#region General\Task\Recipe dataGrid fresh	
		/// <summary>
		/// refresh recipe table data
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_RecipeRefresh_Click(object sender, RoutedEventArgs e)
		{
			client.SendMessage(Identity.definedCommand, Identity.initPageTask, "");
		}
		/// <summary>
		/// refresh batchsamplerule table data
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_BatchRuleRefresh_Click(object sender, RoutedEventArgs e)
		{
			batchSampleRuleDetailMode = "BatchSampleRuleDetail";
			client.SendMessage(Identity.definedCommand, Identity.select_BatchSampleRuleByIndex, ((batchSampleRuleDetail_Index - 1) * batchSampleRuleDetail_Pagenum) + ";" + batchSampleRuleDetail_Index * batchSampleRuleDetail_Pagenum);
		}
		/// <summary>
		/// refresh stripsamplerule table data
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_StripRuleRefresh_Click(object sender, RoutedEventArgs e)
		{
			client.SendMessage(Identity.definedCommand, Identity.select_StripSampleRuleByIndex, ((stripSampleRuleDetail_Index - 1) * stripSampleRuleDetail_Pagenum) + ";" + stripSampleRuleDetail_Index * stripSampleRuleDetail_Pagenum);
		}
		#endregion

		#region General\Task dataGrid LoadingRow
		/// <summary>
		/// general task table data display different colors according to task state
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_GeneralTaskList_LoadingRow(object sender, DataGridRowEventArgs e)
		{
			var task = e.Row.Item as Tasks;
			if (task != null)
			{
				if (task.Status == "1")
				{
					e.Row.Background = new SolidColorBrush(Colors.AliceBlue);
				}
				else if (task.Status == "2")
				{
					e.Row.Background = new SolidColorBrush(Colors.CadetBlue);
				}
				else if (task.Status == "3")
				{
					e.Row.Background = new SolidColorBrush(Colors.Green);
				}
				else if (task.Status == "4")
				{
					e.Row.Background = new SolidColorBrush(Colors.LightGray);
				}
			}
		}
		/// <summary>
		/// general strip table data display different colors according to strip state
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_GeneralStripList_LoadingRow(object sender, DataGridRowEventArgs e)
		{
			var strip = e.Row.Item as Strips;
			if (strip != null)
			{
				if (strip.Status == "0")
				{
					e.Row.Background = new SolidColorBrush(Colors.AliceBlue);
				}
				if (strip.Status == "1")
				{
					e.Row.Background = new SolidColorBrush(Colors.CadetBlue);
				}
				if (strip.Status == "2")
				{
					e.Row.Background = new SolidColorBrush(Colors.Green);
				}
				if (strip.Status == "3")
				{
					e.Row.Background = new SolidColorBrush(Colors.LightGray);
				}
				if (strip.Status == "-1")
				{
					e.Row.Background = new SolidColorBrush(Colors.Red);
				}
			}
		}
		/// <summary>
		/// Task task table data display different colors according to task state
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_TaskList_LoadingRow(object sender, DataGridRowEventArgs e)
		{
			var task = e.Row.Item as Tasks;
			if (task != null)
			{
				if (task.Status == "1")
				{
					e.Row.Background = new SolidColorBrush(Colors.AliceBlue);
				}
				else if (task.Status == "2")
				{
					e.Row.Background = new SolidColorBrush(Colors.CadetBlue);
				}
				else if (task.Status == "3")
				{
					e.Row.Background = new SolidColorBrush(Colors.Green);
				}
				else if (task.Status == "4")
				{
					e.Row.Background = new SolidColorBrush(Colors.LightGray);
				}
			}
		}
		/// <summary>
		/// Task strip table data display different colors according to strip state
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_StripDetail_LoadingRow(object sender, DataGridRowEventArgs e)
		{
			var strip = e.Row.Item as Strips;
			if (strip != null)
			{
				if (strip.Status == "0")
				{
					e.Row.Background = new SolidColorBrush(Colors.AliceBlue);
				}
				if (strip.Status == "1")
				{
					e.Row.Background = new SolidColorBrush(Colors.CadetBlue);
				}
				if (strip.Status == "2")
				{
					e.Row.Background = new SolidColorBrush(Colors.Green);
				}
				if (strip.Status == "3")
				{
					e.Row.Background = new SolidColorBrush(Colors.LightGray);
				}
				if (strip.Status == "-1")
				{
					e.Row.Background = new SolidColorBrush(Colors.Red);
				}
			}
		}
		/// <summary>
		/// popuptask strip table data display different colors according to strip state
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_TaskEditStrip_LoadingRow(object sender, DataGridRowEventArgs e)
		{
			var strip = e.Row.Item as DataRowView;
			if (strip != null)
			{
				if (strip[STRIP_INFO.fd_status].ToString() == "0")
				{
					e.Row.Background = new SolidColorBrush(Colors.AliceBlue);
				}
				if (strip[STRIP_INFO.fd_status].ToString() == "1")
				{
					e.Row.Background = new SolidColorBrush(Colors.CadetBlue);
				}
				if (strip[STRIP_INFO.fd_status].ToString() == "2")
				{
					e.Row.Background = new SolidColorBrush(Colors.Green);
				}
				if (strip[STRIP_INFO.fd_status].ToString() == "3")
				{
					e.Row.Background = new SolidColorBrush(Colors.LightGray);
				}
				if (strip[STRIP_INFO.fd_status].ToString() == "-1")
				{
					e.Row.Background = new SolidColorBrush(Colors.Red);
				}
			}
		}
		#endregion

		#region General/Task task selectionChanged
		/// <summary>
		/// uncheck row information
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_GeneralTaskList_MouseDown(object sender, MouseButtonEventArgs e)
		{
			dataGrid_GeneralTaskList.SelectedItem = null;
		}
		/// <summary>
		/// general task select a task
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_GeneralTaskList_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			var curTask = dataGrid_GeneralTaskList.SelectedItem as Tasks;
			if (dataGrid_GeneralTaskList.SelectedItem != null && curTask != null)
			{
				string task_No = curTask.TaskNo;
				generalOrEditTask = "generalTask";
				generalOrEditStrip = "generalStrip";
				generaStripTaskNo = task_No;
				client.SendMessage(Identity.definedCommand, Identity.select_STRIP_INFOByTaskNo, task_No + ";" + ((generalStrip_Index - 1) * generalStrip_Pagenum) + ";" + generalStrip_Index * generalStrip_Pagenum);
			}
		}
		/// <summary>
		/// task task select a task
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_TaskList_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			var curTask = dataGrid_TaskList.SelectedItem as Tasks;
			if (dataGrid_TaskList.SelectedItem != null && curTask != null)
			{
				string task_No = curTask.TaskNo;
				generalOrEditTask = "taskTask";
				generalOrEditStrip = "taskStrip";
				taskStripTaskNo = task_No;
				client.SendMessage(Identity.definedCommand, Identity.select_STRIP_INFOByTaskNo, task_No + ";" + ((taskStrip_Index - 1) * taskStrip_Pagenum) + ";" + taskStrip_Index * taskStrip_Pagenum);
			}
		}
		#endregion
		
		#region Task batches handle//temprorily useless,reserve
		private void UserControlTaskBatches_EditBatches(object sender, EditBatchesEventArgs e)
		{

		}
		private void btn_SaveBatch_Click(object sender, RoutedEventArgs e)
		{
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_eventNo, typeof(string));
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_stripNo, typeof(string));
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_batchNo, typeof(string));
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_taskNo, typeof(string));
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_stripSampleType, typeof(string));
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_stripThk, typeof(string));
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_stripWidth, typeof(string));
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_stripIdm, typeof(string));
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_stripWeight, typeof(string));
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_curStatus, typeof(string));
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_loadTime, typeof(string));
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_finTime, typeof(string));
			//dataTableBatchInfo.Columns.Add(BATCH_INFO.fd_updateTime, typeof(string));
		}


		private void btn_EditStrips_Click(object sender, RoutedEventArgs e)
		{
			//Popup_StripsDetail.IsOpen = true;
		}

		#endregion

		#region Recipe handle
		#region Task Select recipe
		/// <summary>
		/// Task Bind recipe Select button
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_SelectRecipe_Click(object sender, RoutedEventArgs e)
		{
			recipeDetailMode = "RecipeBind";
			Popup_Recipe.IsOpen = true;
			//设置Popup的高度		
			DependencyObject parent = Popup_Recipe.Child;
			do
			{
				parent = VisualTreeHelper.GetParent(parent);
				if (parent != null && parent.ToString() == "System.Windows.Controls.Primitives.PopupRoot")
				{
					var element = parent as FrameworkElement;
					element.Height = 640;
					break;
				}
			}
			while (parent != null);
			recipeBind_Index = 1;
			textBox_BindRecipePage.Text = recipeBind_Index.ToString();
			client.SendMessage(Identity.definedCommand, Identity.select_RecipeByIndex, ((recipeBind_Index - 1) * recipeBind_Pagenum) + ";" + recipeBind_Index * recipeBind_Pagenum);
		}
		/// <summary>
		/// PopupRecipe query recipe by parameter
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_BindRecipeSelect_Click(object sender, RoutedEventArgs e)
		{
			try
			{				
				string pipeMinOD = textBox_BindRecipePipeMinOd.Text.ToString();
				string pipeMaxOD = textBox_BindRecipePipeMaxOd.Text.ToString();
				string pipeMinTHK = textBox_BindRecipePipeMinThickeness.Text.ToString();
				string pipeMaxTHK = textBox_BindRecipePipeMaxThickeness.Text.ToString();
				string recipeNo = textBox_BindRecipeRecipeNo.Text.ToString();
				string steelGrade = textBox_BindRecipeSteelGrade.Text.ToString();

				string strsql = string.Format("select * from (select ROWNUM rn, d.* from (select * from {0} where 1=1", RECIPE_INFO.tableName);
				if (recipeNo != "")
				{
					strsql += string.Format(" and {0} like '%{1}%'", RECIPE_INFO.fd_recipeNo, recipeNo);
				}

				if (steelGrade != "")
				{
					strsql += string.Format(" and {0}='{1}'", RECIPE_INFO.fd_steelGrade, steelGrade);
				}

				if (pipeMinTHK != "" && pipeMaxTHK != "")
				{
					strsql += string.Format(" and {0} >='", RECIPE_INFO.fd_pipeThickness) + pipeMinTHK + string.Format("' and {0}<='", RECIPE_INFO.fd_pipeThickness) + pipeMaxTHK+"'";
				}
				else if (pipeMinTHK == "" && pipeMaxTHK != "")
				{
					strsql += string.Format("' and {0}<='", RECIPE_INFO.fd_pipeThickness) + pipeMaxTHK+"'";
				}
				else if (pipeMinTHK != "" && pipeMaxTHK == "")
				{
					strsql += string.Format(" and {0} >='", RECIPE_INFO.fd_pipeThickness) + pipeMinTHK+"'";
				}

				if (pipeMinOD != "" && pipeMaxOD != "")
				{
					strsql += string.Format(" and {0} >=", RECIPE_INFO.fd_pipeOd) + pipeMinOD + string.Format(" and {0}<=", RECIPE_INFO.fd_pipeOd) + pipeMaxOD;
				}
				else if (pipeMinOD == "" && pipeMaxOD != "")
				{
					strsql += string.Format("' and {0}<=", RECIPE_INFO.fd_pipeOd) + pipeMaxOD;
				}
				else if (pipeMinOD != "" && pipeMaxOD == "")
				{
					strsql += string.Format(" and {0} >=", RECIPE_INFO.fd_pipeOd) + pipeMinOD;
				}				
				strsql += string.Format(" order by {0} desc,{1} desc) d)", RECIPE_INFO.fd_modifyDate, RECIPE_INFO.fd_createDate);
				popupRecipePageSql = strsql;
				recipeDetailMode = "RecipeBind";
				recipeBind_Index = 1;
				textBox_BindRecipePage.Text = recipeBind_Index.ToString();
				client.SendMessage(Identity.definedCommand, Identity.selectRecipeByParameters, popupRecipePageSql + ";0;20");
				LogHelper.WriteLog("btn_BindRecipeSelect_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_BindRecipeSelect_Click", ex);
			}
		}
		/// <summary>
		/// recipe SelectionChanged
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_BindRecipe_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (dataGrid_BindRecipe.SelectedItem != null)
			{
				var recipeDRV = dataGrid_BindRecipe.SelectedItem as DataRowView;
				TextBox_BindRecipe_RecipeNo.Text = recipeDRV[RECIPE_INFO.fd_recipeNo].ToString();
				TextBox_BindRecipe_RecipeName.Text = recipeDRV[RECIPE_INFO.fd_recipeName].ToString();
				TextBox_BindRecipe_SteelGrade.Text = recipeDRV[RECIPE_INFO.fd_steelGrade].ToString();
				TextBox_BindRecipe_SteelClass.Text = recipeDRV[RECIPE_INFO.fd_steelClass].ToString();
				TextBox_BindRecipe_StripThickness.Text = recipeDRV[RECIPE_INFO.fd_stripThickness].ToString();
				TextBox_BindRecipe_StripWidth.Text = recipeDRV[RECIPE_INFO.fd_stripWidth].ToString();
				TextBox_BindRecipe_PipeOd.Text = recipeDRV[RECIPE_INFO.fd_pipeOd].ToString();
				TextBox_BindRecipe_PipeThickness.Text = recipeDRV[RECIPE_INFO.fd_pipeThickness].ToString();
				TextBox_BindRecipe_YeildStrength.Text = recipeDRV[RECIPE_INFO.fd_yeildStrength].ToString();
				TextBox_BindRecipe_AccPressure1.Text = recipeDRV[RECIPE_INFO.fd_accPrPressure_1].ToString();
				TextBox_BindRecipe_AccPressure2.Text = recipeDRV[RECIPE_INFO.fd_accPrPressure_2].ToString();
				TextBox_BindRecipe_StripWidthTarget.Text = recipeDRV[RECIPE_INFO.fd_stripWdTarget].ToString();
				TextBox_BindRecipe_EmCuttingSpeed.Text = recipeDRV[RECIPE_INFO.fd_emCuttingSpd].ToString();
				TextBox_BindRecipe_EmChipload.Text = recipeDRV[RECIPE_INFO.fd_emChipload].ToString();
				TextBox_BindRecipe_Sa1Power.Text = recipeDRV[RECIPE_INFO.fd_sa1Power].ToString();
				TextBox_BindRecipe_Sa1Temp.Text = recipeDRV[RECIPE_INFO.fd_sa1Temp].ToString();
				TextBox_BindRecipe_Sa1Height.Text = recipeDRV[RECIPE_INFO.fd_sa1Height].ToString();
				TextBox_BindRecipe_Sa1Freq.Text = recipeDRV[RECIPE_INFO.fd_sa1Freq].ToString();
				TextBox_BindRecipe_Sa2Power.Text = recipeDRV[RECIPE_INFO.fd_sa2Power].ToString();
				TextBox_BindRecipe_Sa2Temp.Text = recipeDRV[RECIPE_INFO.fd_sa2Temp].ToString();
				TextBox_BindRecipe_Sa2Height.Text = recipeDRV[RECIPE_INFO.fd_sa2Height].ToString();
				TextBox_BindRecipe_Sa2Freq.Text = recipeDRV[RECIPE_INFO.fd_sa2Freq].ToString();
				TextBox_BindRecipe_Sa3Power.Text = recipeDRV[RECIPE_INFO.fd_sa3Power].ToString();
				TextBox_BindRecipe_Sa3Temp.Text = recipeDRV[RECIPE_INFO.fd_sa3Temp].ToString();
				TextBox_BindRecipe_Sa3Height.Text = recipeDRV[RECIPE_INFO.fd_sa3Height].ToString();
				TextBox_BindRecipe_Sa3Freq.Text = recipeDRV[RECIPE_INFO.fd_sa3Freq].ToString();
				TextBox_BindRecipe_Sa4Power.Text = recipeDRV[RECIPE_INFO.fd_sa4Power].ToString();
				TextBox_BindRecipe_Sa4Temp.Text = recipeDRV[RECIPE_INFO.fd_sa4Temp].ToString();
				TextBox_BindRecipe_Sa4Height.Text = recipeDRV[RECIPE_INFO.fd_sa4Height].ToString();
				TextBox_BindRecipe_Sa4Freq.Text = recipeDRV[RECIPE_INFO.fd_sa4Freq].ToString();
				TextBox_BindRecipe_HfwLineSpeed.Text = recipeDRV[RECIPE_INFO.fd_hfwLineSpeed].ToString();
				TextBox_BindRecipe_HfwPower.Text = recipeDRV[RECIPE_INFO.fd_HfwPower].ToString();
				TextBox_BindRecipe_HfwFreq.Text = recipeDRV[RECIPE_INFO.fd_HfwFreq].ToString();
				TextBox_BindRecipe_HfwVeeX.Text = recipeDRV[RECIPE_INFO.fd_HfwVee_X].ToString();
				TextBox_BindRecipe_SustCw1.Text = recipeDRV[RECIPE_INFO.fd_sustCw1].ToString();
				TextBox_BindRecipe_SustCw2.Text = recipeDRV[RECIPE_INFO.fd_sustCw2].ToString();
			}
		}
		/// <summary>
		/// confirm whether recipeno is imported into task parameters
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_BindRecipe_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
		{
			if (MessageBox.Show("Are you sure you want to import recipeNo into Task?", "IMPORT", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
			{
				if (dataGrid_BindRecipe.SelectedItem != null)
				{
					var recipeBind = dataGrid_BindRecipe.SelectedItem as DataRowView;
					if (recipeBind != null)
					{
						string recipeNo = recipeBind.Row[RECIPE_INFO.fd_recipeNo].ToString();
						textBox_RecipeNo.Text = recipeNo;
						//textBox_BindRecipeNo.Text = recipeNo;
					}
				}
			}
		}
		/// <summary>
		/// recipe page down
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_DownPage_BindRecipe_Click(object sender, RoutedEventArgs e)
		{
			if (recipeBind_index_isChange && Convert.ToInt32(textBox_BindRecipePage.Text) < Convert.ToInt32(textBox_BindRecipeTotalPages.Text))
			{
				recipeBind_Index++;
				textBox_BindRecipePage.Text = recipeBind_Index.ToString();
				if (popupRecipePageSql == "")
				{
					popupRecipePageSql = string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} order by {1} desc,{2} desc) a)",
				  RECIPE_INFO.tableName, RECIPE_INFO.fd_modifyDate, RECIPE_INFO.fd_createDate);
				}
				recipeDetailMode = "RecipeBind";
				client.SendMessage(Identity.definedCommand, Identity.selectRecipeByParameters, popupRecipePageSql+";"+((recipeBind_Index - 1) * recipeBind_Pagenum) + ";" + recipeBind_Index * recipeBind_Pagenum);
			}
		}
		/// <summary>
		/// recipe page up
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_UpPage_BindRecipe_Click(object sender, RoutedEventArgs e)
		{
			if (recipeBind_Index > 1)
			{
				recipeBind_Index--;
				textBox_BindRecipePage.Text = recipeBind_Index.ToString();
				if (popupRecipePageSql == "")
				{
					popupRecipePageSql = string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} order by {1} desc,{2} desc) a)",
				  RECIPE_INFO.tableName, RECIPE_INFO.fd_modifyDate, RECIPE_INFO.fd_createDate);
				}
				recipeDetailMode = "RecipeBind";
				client.SendMessage(Identity.definedCommand, Identity.selectRecipeByParameters, popupRecipePageSql + ";" + ((recipeBind_Index - 1) * recipeBind_Pagenum) + ";" + recipeBind_Index * recipeBind_Pagenum);
			}
			
		}
		/// <summary>
		/// close Popup recipe
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_Recipe_Close_Click(object sender, RoutedEventArgs e)
		{
			Popup_Recipe.IsOpen = false;
		}
		#endregion

		#region Recipe Detail
		/// <summary>
		/// uncheck row information
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_RecipeDetail_MouseDown(object sender, MouseButtonEventArgs e)
		{
			dataGrid_RecipeDetail.SelectedItem = null;
		}
		/// <summary>
		/// recipeDetail selectionChanged
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_RecipeDetail_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			try
			{
				TextBox_RecipeNo.IsEnabled = false;
				StackPanel_Edit_Recipe.IsEnabled = false;
				if (dataGrid_RecipeDetail.SelectedItem != null)
				{
					var recipeDetail = dataGrid_RecipeDetail.SelectedItem as DataRowView;
					if (recipeDetail != null)
					{
						string recipeNo = recipeDetail.Row[RECIPE_INFO.fd_recipeNo].ToString();
						TextBox_RecipeNo.Text = recipeNo;
						TextBox_RecipeName.Text = recipeDetail[RECIPE_INFO.fd_recipeName].ToString();
						TextBox_SteelGrade.Text = recipeDetail[RECIPE_INFO.fd_steelGrade].ToString();
						TextBox_SteelClass.Text = recipeDetail[RECIPE_INFO.fd_steelClass].ToString();
						TextBox_StripThickness.Text = recipeDetail[RECIPE_INFO.fd_stripThickness].ToString();
						TextBox_StripWidth.Text = recipeDetail[RECIPE_INFO.fd_stripWidth].ToString();
						TextBox_PipeOd.Text = recipeDetail[RECIPE_INFO.fd_pipeOd].ToString();
						TextBox_PipeThickness.Text = recipeDetail[RECIPE_INFO.fd_pipeThickness].ToString();
						//TextBox_PipeDiameter.Text = recipeDetail[RECIPE_INFO.fd_pipeDiameter].ToString();
						TextBox_YeildStrength.Text = recipeDetail[RECIPE_INFO.fd_yeildStrength].ToString();
						TextBox_AccPressure1.Text = recipeDetail[RECIPE_INFO.fd_accPrPressure_1].ToString();
						TextBox_AccPressure2.Text = recipeDetail[RECIPE_INFO.fd_accPrPressure_2].ToString();
						TextBox_EmCuttingSpeed.Text = recipeDetail[RECIPE_INFO.fd_emCuttingSpd].ToString();
						TextBox_EmChipload.Text = recipeDetail[RECIPE_INFO.fd_emChipload].ToString();
						TextBox_Sa1Power.Text = recipeDetail[RECIPE_INFO.fd_sa1Power].ToString();
						TextBox_Sa1Temp.Text = recipeDetail[RECIPE_INFO.fd_sa1Temp].ToString();
						TextBox_Sa1Height.Text = recipeDetail[RECIPE_INFO.fd_sa1Height].ToString();
						TextBox_Sa1Freq.Text = recipeDetail[RECIPE_INFO.fd_sa1Freq].ToString();
						TextBox_Sa2Power.Text = recipeDetail[RECIPE_INFO.fd_sa2Power].ToString();
						TextBox_Sa2Temp.Text = recipeDetail[RECIPE_INFO.fd_sa2Temp].ToString();
						TextBox_Sa2Height.Text = recipeDetail[RECIPE_INFO.fd_sa2Height].ToString();
						TextBox_Sa2Freq.Text = recipeDetail[RECIPE_INFO.fd_sa2Freq].ToString();
						TextBox_Sa3Power.Text = recipeDetail[RECIPE_INFO.fd_sa3Power].ToString();
						TextBox_Sa3Temp.Text = recipeDetail[RECIPE_INFO.fd_sa3Temp].ToString();
						TextBox_Sa3Height.Text = recipeDetail[RECIPE_INFO.fd_sa3Height].ToString();
						TextBox_Sa3Freq.Text = recipeDetail[RECIPE_INFO.fd_sa3Freq].ToString();
						TextBox_Sa4Power.Text = recipeDetail[RECIPE_INFO.fd_sa4Power].ToString();
						TextBox_Sa4Temp.Text = recipeDetail[RECIPE_INFO.fd_sa4Temp].ToString();
						TextBox_Sa4Height.Text = recipeDetail[RECIPE_INFO.fd_sa4Height].ToString();
						TextBox_Sa4Freq.Text = recipeDetail[RECIPE_INFO.fd_sa4Freq].ToString();
						TextBox_HfwLineSpeed.Text = recipeDetail[RECIPE_INFO.fd_hfwLineSpeed].ToString();
						TextBox_HfwPower.Text = recipeDetail[RECIPE_INFO.fd_HfwPower].ToString();
						TextBox_HfwFreq.Text = recipeDetail[RECIPE_INFO.fd_HfwFreq].ToString();
						TextBox_HfwVeeX.Text = recipeDetail[RECIPE_INFO.fd_HfwVee_X].ToString();
						TextBox_SustCw1.Text = recipeDetail[RECIPE_INFO.fd_sustCw1].ToString();
						TextBox_SustCw2.Text = recipeDetail[RECIPE_INFO.fd_sustCw2].ToString();
						TextBox_StripWidthTarget.Text = recipeDetail[RECIPE_INFO.fd_stripWdTarget].ToString();
						TextBox_HfwMode.Text = recipeDetail[RECIPE_INFO.fd_HfwMode].ToString();
						TextBox_HfwpreHeatPower.Text = recipeDetail[RECIPE_INFO.fd_HfwPreHeatPower].ToString();
						TextBox_HfwTemperature.Text = recipeDetail[RECIPE_INFO.fd_HfwTemperature].ToString();
						TextBox_HfwSpcGain.Text = recipeDetail[RECIPE_INFO.fd_HfwSPCGain].ToString();
						TextBox_HfwSpcSlop.Text = recipeDetail[RECIPE_INFO.fd_HfwSPCSlope].ToString();
						TextBox_CreateDate.Text = recipeDetail[RECIPE_INFO.fd_createDate].ToString();
						TextBox_ModifyDate.Text = recipeDetail[RECIPE_INFO.fd_modifyDate].ToString();
						TextBox_RecipeStatus.Text = recipeDetail[RECIPE_INFO.fd_recipeStatus].ToString();
						TextBox_Creater.Text = recipeDetail[RECIPE_INFO.fd_creater].ToString();
						TextBox_ModifyUser.Text = recipeDetail[RECIPE_INFO.fd_modifyUser].ToString();
					}
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		/// <summary>
		/// fuzzy query recipe table data
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_RecipeSelect_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				string pipeMinOD = textBox_RecipePipeMinOd.Text.ToString();
				string pipeMaxOD = textBox_RecipePipeMaxOd.Text.ToString();
				string pipeMinTHK = textBox_RecipePipeMinThickeness.Text.ToString();
				string pipeMaxTHK = textBox_RecipePipeMaxThickeness.Text.ToString();
				string recipeNo = textBox_RecipeRecipeNo.Text.ToString();
				string steelGrade = textBox_RecipeSteelGrade.Text.ToString();

				string strsql = string.Format("select * from (select ROWNUM rn, d.* from (select * from {0} where 1=1", RECIPE_INFO.tableName);
				if (recipeNo != "")
				{
					strsql += string.Format(" and {0} like '%{1}%'", RECIPE_INFO.fd_recipeNo, recipeNo);
				}

				if (steelGrade != "")
				{
					strsql += string.Format(" and {0}='{1}'", RECIPE_INFO.fd_steelGrade, steelGrade);
				}

				if (pipeMinTHK != "" && pipeMaxTHK != "")
				{
					strsql += string.Format(" and {0} >='", RECIPE_INFO.fd_pipeThickness) + pipeMinTHK + string.Format("' and {0}<='", RECIPE_INFO.fd_pipeThickness) + pipeMaxTHK+"'";
				}
				else if (pipeMinTHK == "" && pipeMaxTHK != "")
				{
					strsql += string.Format(" and {0}<='", RECIPE_INFO.fd_pipeThickness) + pipeMaxTHK+"'";
				}
				else if (pipeMinTHK != "" && pipeMaxTHK == "")
				{
					strsql += string.Format(" and {0} >='", RECIPE_INFO.fd_pipeThickness) + pipeMinTHK+"'";
				}

				if (pipeMinOD != "" && pipeMaxOD != "")
				{
					strsql += string.Format(" and {0} >=", RECIPE_INFO.fd_pipeOd) + pipeMinOD + string.Format(" and {0}<=", RECIPE_INFO.fd_pipeOd) + pipeMaxOD;
				}
				else if (pipeMinOD == "" && pipeMaxOD != "")
				{
					strsql += string.Format(" and {0}<=", RECIPE_INFO.fd_pipeOd) + pipeMaxOD;
				}
				else if (pipeMinOD != "" && pipeMaxOD == "")
				{
					strsql += string.Format(" and {0} >=", RECIPE_INFO.fd_pipeOd) + pipeMinOD;
				}
				strsql += string.Format(" order by {0} desc,{1} desc) d)", RECIPE_INFO.fd_modifyDate, RECIPE_INFO.fd_createDate);
				recipeDetailPageSql = strsql;
				recipeDetailMode = "RecipeDetail";
				recipeDetail_Index = 1;
				textBox_RecipePage.Text = recipeDetail_Index.ToString();
				client.SendMessage(Identity.definedCommand, Identity.selectRecipeByParameters, recipeDetailPageSql + ";0;20");
				LogHelper.WriteLog("btn_RecipeSelect_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_RecipeSelect_Click", ex);
			}
		}
		/// <summary>
		/// edit recipeDetail information
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_Edit_Recipe_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				StackPanel_Edit_Recipe.IsEnabled = true;
				TextBox_Creater.IsEnabled = false;
				TextBox_ModifyUser.IsEnabled = false;
				buttonSaveRecipe_EditorNew = "Edit";
				LogHelper.WriteLog("btn_Edit_Recipe_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_Edit_Recipe_Click", ex);
			}

		}
		/// <summary>
		/// new recipeDetail
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_New_recipe_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (MessageBox.Show("Once created, it cannot be deleted. Are you sure you want to create a new recipe?", "New", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.Cancel)
				{
					return;
				}
				var recipeDRV = dataGrid_RecipeDetail.SelectedItem as DataRowView;
				if (dataGrid_RecipeDetail.SelectedItem == null)
				{
					StackPanel_Edit_Recipe.IsEnabled = true;
					TextBox_RecipeNo.IsEnabled = true;
					TextBox_Creater.IsEnabled = false;
					TextBox_ModifyUser.IsEnabled = false;
					TextBox_RecipeNo.Text = "";
					TextBox_RecipeName.Text = "";
					TextBox_SteelGrade.Text = "";
					TextBox_SteelClass.Text = "0";
					TextBox_StripThickness.Text = "";
					TextBox_StripWidth.Text = "";
					TextBox_PipeOd.Text = "";
					TextBox_PipeThickness.Text = "";
					TextBox_PipeDiameter.Text = "";
					TextBox_YeildStrength.Text = "";
					TextBox_AccPressure1.Text = "";
					TextBox_AccPressure2.Text = "";
					TextBox_EmCuttingSpeed.Text = "";
					TextBox_EmChipload.Text = "";
					TextBox_Sa1Power.Text = "";
					TextBox_Sa1Temp.Text = "";
					TextBox_Sa1Height.Text = "";
					TextBox_Sa1Freq.Text = "";
					TextBox_Sa2Power.Text = "";
					TextBox_Sa2Temp.Text = "";
					TextBox_Sa2Height.Text = "";
					TextBox_Sa2Freq.Text = "";
					TextBox_Sa3Power.Text = "";
					TextBox_Sa3Temp.Text = "";
					TextBox_Sa3Height.Text = "";
					TextBox_Sa3Freq.Text = "";
					TextBox_Sa4Power.Text = "";
					TextBox_Sa4Temp.Text = "";
					TextBox_Sa4Height.Text = "";
					TextBox_Sa4Freq.Text = "";
					TextBox_HfwLineSpeed.Text = "";
					TextBox_HfwPower.Text = "";
					TextBox_HfwFreq.Text = "";
					TextBox_HfwVeeX.Text = "";
					TextBox_SustCw1.Text = "";
					TextBox_SustCw2.Text = "";
					TextBox_StripWidthTarget.Text = "";
					TextBox_HfwMode.Text = "";
					TextBox_HfwpreHeatPower.Text = "";
					TextBox_HfwTemperature.Text = "";
					TextBox_HfwSpcGain.Text = "";
					TextBox_HfwSpcSlop.Text = "";
					TextBox_CreateDate.Text = "";
					TextBox_ModifyDate.Text = DateTime.Now.ToString(Formats.GetDateFormat());
					TextBox_RecipeStatus.Text = "0";
					TextBox_Creater.Text = USER_TABLE.user_Name;
					TextBox_ModifyUser.Text = "";
				}
				else
				{
					StackPanel_Edit_Recipe.IsEnabled = true;
					TextBox_RecipeNo.IsEnabled = true;
					TextBox_Creater.IsEnabled = false;
					TextBox_ModifyUser.IsEnabled = false;
					TextBox_RecipeNo.Text = "";
					TextBox_RecipeName.Text = recipeDRV[RECIPE_INFO.fd_recipeName].ToString();
					TextBox_SteelGrade.Text = recipeDRV[RECIPE_INFO.fd_steelGrade].ToString();
					TextBox_SteelClass.Text = recipeDRV[RECIPE_INFO.fd_steelClass].ToString();
					TextBox_StripThickness.Text = recipeDRV[RECIPE_INFO.fd_stripThickness].ToString();
					TextBox_StripWidth.Text = recipeDRV[RECIPE_INFO.fd_stripWidth].ToString();
					TextBox_PipeOd.Text = recipeDRV[RECIPE_INFO.fd_pipeOd].ToString();
					TextBox_PipeThickness.Text = recipeDRV[RECIPE_INFO.fd_pipeThickness].ToString();
					TextBox_PipeDiameter.Text = recipeDRV[RECIPE_INFO.fd_pipeDiameter].ToString();
					TextBox_YeildStrength.Text = recipeDRV[RECIPE_INFO.fd_yeildStrength].ToString();
					TextBox_AccPressure1.Text = recipeDRV[RECIPE_INFO.fd_accPrPressure_1].ToString();
					TextBox_AccPressure2.Text = recipeDRV[RECIPE_INFO.fd_accPrPressure_2].ToString();
					TextBox_EmCuttingSpeed.Text = recipeDRV[RECIPE_INFO.fd_emCuttingSpd].ToString();
					TextBox_EmChipload.Text = recipeDRV[RECIPE_INFO.fd_emChipload].ToString();
					TextBox_Sa1Power.Text = recipeDRV[RECIPE_INFO.fd_sa1Power].ToString();
					TextBox_Sa1Temp.Text = recipeDRV[RECIPE_INFO.fd_sa1Temp].ToString();
					TextBox_Sa1Height.Text = recipeDRV[RECIPE_INFO.fd_sa1Height].ToString();
					TextBox_Sa1Freq.Text = recipeDRV[RECIPE_INFO.fd_sa1Freq].ToString();
					TextBox_Sa2Power.Text = recipeDRV[RECIPE_INFO.fd_sa2Power].ToString();
					TextBox_Sa2Temp.Text = recipeDRV[RECIPE_INFO.fd_sa2Temp].ToString();
					TextBox_Sa2Height.Text = recipeDRV[RECIPE_INFO.fd_sa2Height].ToString();
					TextBox_Sa2Freq.Text = recipeDRV[RECIPE_INFO.fd_sa2Freq].ToString();
					TextBox_Sa3Power.Text = recipeDRV[RECIPE_INFO.fd_sa3Power].ToString();
					TextBox_Sa3Temp.Text = recipeDRV[RECIPE_INFO.fd_sa3Temp].ToString();
					TextBox_Sa3Height.Text = recipeDRV[RECIPE_INFO.fd_sa3Height].ToString();
					TextBox_Sa3Freq.Text = recipeDRV[RECIPE_INFO.fd_sa3Freq].ToString();
					TextBox_Sa4Power.Text = recipeDRV[RECIPE_INFO.fd_sa4Power].ToString();
					TextBox_Sa4Temp.Text = recipeDRV[RECIPE_INFO.fd_sa4Temp].ToString();
					TextBox_Sa4Height.Text = recipeDRV[RECIPE_INFO.fd_sa4Height].ToString();
					TextBox_Sa4Freq.Text = recipeDRV[RECIPE_INFO.fd_sa4Freq].ToString();
					TextBox_HfwLineSpeed.Text = recipeDRV[RECIPE_INFO.fd_hfwLineSpeed].ToString();
					TextBox_HfwPower.Text = recipeDRV[RECIPE_INFO.fd_HfwPower].ToString();
					TextBox_HfwFreq.Text = recipeDRV[RECIPE_INFO.fd_HfwFreq].ToString();
					TextBox_HfwVeeX.Text = recipeDRV[RECIPE_INFO.fd_HfwVee_X].ToString();
					TextBox_SustCw1.Text = recipeDRV[RECIPE_INFO.fd_sustCw1].ToString();
					TextBox_SustCw2.Text = recipeDRV[RECIPE_INFO.fd_sustCw2].ToString();
					TextBox_StripWidthTarget.Text = recipeDRV[RECIPE_INFO.fd_stripWdTarget].ToString();
					TextBox_HfwMode.Text = recipeDRV[RECIPE_INFO.fd_HfwMode].ToString();
					TextBox_HfwpreHeatPower.Text = recipeDRV[RECIPE_INFO.fd_HfwPreHeatPower].ToString();
					TextBox_HfwTemperature.Text = recipeDRV[RECIPE_INFO.fd_HfwTemperature].ToString();
					TextBox_HfwSpcGain.Text = recipeDRV[RECIPE_INFO.fd_HfwSPCGain].ToString();
					TextBox_HfwSpcSlop.Text = recipeDRV[RECIPE_INFO.fd_HfwSPCSlope].ToString();
					TextBox_CreateDate.Text = DateTime.Now.ToString(Formats.GetDateFormat());
					TextBox_ModifyDate.Text = "";
					TextBox_RecipeStatus.Text = "0";
					TextBox_Creater.Text = USER_TABLE.user_Name;
					TextBox_ModifyUser.Text = "";
				}

				buttonSaveRecipe_EditorNew = "New";
				LogHelper.WriteLog("btn_New_recipe_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_New_recipe_Click", ex);
			}

		}
		/// <summary>
		/// save recipeDetail
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_Save_recipe_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (TextBox_RecipeNo.Text.ToString() == "")
				{
					MessageBox.Show("Recipe No can not be null");
					return;
				}
				if (TextBox_RecipeName.Text.ToString() == "")
				{
					MessageBox.Show("Recipe name can not be null");
					return;
				}

				bool s = checkRecipeValue();
				if (!s)
					return;

				DataTable dataTableRecipe = new DataTable();
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_recipeName, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_recipeNo, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_steelGrade, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_steelClass, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_stripThickness, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_stripWidth, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_pipeOd, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_pipeThickness, typeof(string));
				//dataTableRecipe.Columns.Add(RECIPE_INFO.fd_pipeDiameter, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_yeildStrength, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_accPrPressure_1, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_accPrPressure_2, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_emCuttingSpd, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_emChipload, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa1Power, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa1Temp, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa1Height, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa1Freq, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa2Power, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa2Temp, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa2Height, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa2Freq, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa3Power, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa3Temp, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa3Height, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa3Freq, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa4Power, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa4Temp, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa4Height, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sa4Freq, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_hfwLineSpeed, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_HfwPower, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_HfwFreq, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_HfwVee_X, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sustCw1, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_sustCw2, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_stripWdTarget, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_HfwMode, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_HfwPreHeatPower, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_HfwTemperature, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_HfwSPCGain, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_HfwSPCSlope, typeof(string));
				//dataTableRecipe.Columns.Add(RECIPE_INFO.fd_parameter6, typeof(string));
				//dataTableRecipe.Columns.Add(RECIPE_INFO.fd_parameter7, typeof(string));
				//dataTableRecipe.Columns.Add(RECIPE_INFO.fd_parameter8, typeof(string));
				//dataTableRecipe.Columns.Add(RECIPE_INFO.fd_parameter9, typeof(string));
				//dataTableRecipe.Columns.Add(RECIPE_INFO.fd_parameter10, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_createDate, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_modifyDate, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_recipeStatus, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_creater, typeof(string));
				dataTableRecipe.Columns.Add(RECIPE_INFO.fd_modifyUser, typeof(string));

				dataTableRecipe.Rows.Add(TextBox_RecipeName.Text.ToString(), TextBox_RecipeNo.Text.ToString(), TextBox_SteelGrade.Text.ToString(), TextBox_SteelClass.Text.ToString(), TextBox_StripThickness.Text.ToString(), TextBox_StripWidth.Text.ToString(), TextBox_PipeOd.Text.ToString(), TextBox_PipeThickness.Text.ToString(),
					TextBox_YeildStrength.Text.ToString(), TextBox_AccPressure1.Text.ToString(), TextBox_AccPressure2.Text.ToString(), TextBox_EmCuttingSpeed.Text.ToString(), TextBox_EmChipload.Text.ToString(), TextBox_Sa1Power.Text.ToString(), TextBox_Sa1Temp.Text.ToString(), TextBox_Sa1Height.Text.ToString(), TextBox_Sa1Freq.Text.ToString(),
					TextBox_Sa2Power.Text.ToString(), TextBox_Sa2Temp.Text.ToString(), TextBox_Sa2Height.Text.ToString(), TextBox_Sa2Freq.Text.ToString(), TextBox_Sa3Power.Text.ToString(), TextBox_Sa3Temp.Text.ToString(), TextBox_Sa3Height.Text.ToString(), TextBox_Sa3Freq.Text.ToString(), TextBox_Sa4Power.Text.ToString(), TextBox_Sa4Temp.Text.ToString(), TextBox_Sa4Height.Text.ToString(), TextBox_Sa4Freq.Text.ToString(),
					TextBox_HfwLineSpeed.Text.ToString(), TextBox_HfwPower.Text.ToString(), TextBox_HfwFreq.Text.ToString(), TextBox_HfwVeeX.Text.ToString(), TextBox_SustCw1.Text.ToString(), TextBox_SustCw2.Text.ToString(), TextBox_StripWidthTarget.Text.ToString(), TextBox_HfwMode.Text.ToString(), TextBox_HfwpreHeatPower.Text.ToString(), TextBox_HfwTemperature.Text.ToString(), TextBox_HfwSpcGain.Text.ToString(), TextBox_HfwSpcSlop.Text.ToString(),TextBox_CreateDate.Text.ToString(),
					TextBox_ModifyDate.Text.ToString(), TextBox_RecipeStatus.Text.ToString(), TextBox_Creater.Text.ToString(), TextBox_ModifyUser.Text.ToString());

				string jsonRecipe = "";
				if (MessageBox.Show("Are you sure you want to save the recipe?", "EDIT", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
				{
					if (buttonSaveRecipe_EditorNew == "New")
					{
						recipeDetailMode = "RecipeDetail";
						dataTableRecipe.Rows[0][RECIPE_INFO.fd_createDate] = DateTime.Now.ToString(Formats.GetDateFormat());
						dataTableRecipe.Rows[0][RECIPE_INFO.fd_creater] = USER_TABLE.user_Name;
						jsonRecipe = JsonHelper.SerializeObject(dataTableRecipe);
						client.SendMessage(Identity.definedCommand, Identity.insert_Recipe, jsonRecipe);
					}
					else if (buttonSaveRecipe_EditorNew == "Edit")
					{
						recipeDetailMode = "RecipeDetail";
						dataTableRecipe.Rows[0][RECIPE_INFO.fd_modifyDate] = DateTime.Now.ToString(Formats.GetDateFormat());
						dataTableRecipe.Rows[0][RECIPE_INFO.fd_modifyUser] = USER_TABLE.user_Name;
						jsonRecipe = JsonHelper.SerializeObject(dataTableRecipe);
						client.SendMessage(Identity.definedCommand, Identity.edit_Recipe, jsonRecipe);
					}
				}
				LogHelper.WriteLog("btn_Save_recipe_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_Save_recipe_Click", ex);
			}
		}


		private bool checkRecipeValue()
		{
			bool r = true;
			if(!double.TryParse(TextBox_StripThickness.Text.ToString(),out double resutl1))
			{
				if(TextBox_StripThickness.Text.ToString().Contains(","))
				{
					TextBox_StripThickness.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_StripWidth.Text.ToString(), out double resutl2))
			{
				if (TextBox_StripWidth.Text.ToString().Contains(","))
				{
					TextBox_StripWidth.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_PipeOd.Text.ToString(), out double resutl3))
			{
				if (TextBox_PipeOd.Text.ToString().Contains(","))
				{
					TextBox_PipeOd.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_PipeThickness.Text.ToString(), out double resutl4))
			{
				if (TextBox_PipeThickness.Text.ToString().Contains(","))
				{
					TextBox_PipeThickness.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_YeildStrength.Text.ToString(), out double resutl5))
			{
				if (TextBox_YeildStrength.Text.ToString().Contains(","))
				{
					TextBox_YeildStrength.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_AccPressure1.Text.ToString(), out double resutl6))
			{
				if (TextBox_AccPressure1.Text.ToString().Contains(","))
				{
					TextBox_AccPressure1.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_AccPressure2.Text.ToString(), out double resutl7))
			{
				if (TextBox_AccPressure2.Text.ToString().Contains(","))
				{
					TextBox_AccPressure2.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_EmCuttingSpeed.Text.ToString(), out double resutl8))
			{
				if (TextBox_EmCuttingSpeed.Text.ToString().Contains(","))
				{
					TextBox_EmCuttingSpeed.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_EmChipload.Text.ToString(), out double resutl9))
			{
				if (TextBox_EmChipload.Text.ToString().Contains(","))
				{
					TextBox_EmChipload.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa1Power.Text.ToString(), out double resutl10))
			{
				if (TextBox_Sa1Power.Text.ToString().Contains(","))
				{
					TextBox_Sa1Power.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa1Temp.Text.ToString(), out double resutl11))
			{
				if (TextBox_Sa1Temp.Text.ToString().Contains(","))
				{
					TextBox_Sa1Temp.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa1Height.Text.ToString(), out double resutl12))
			{
				if (TextBox_Sa1Height.Text.ToString().Contains(","))
				{
					TextBox_Sa1Height.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}

				
			}

			if (!double.TryParse(TextBox_Sa1Freq.Text.ToString(), out double resutl13))
			{
				if (TextBox_Sa1Freq.Text.ToString().Contains(","))
				{
					TextBox_Sa1Freq.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa2Power.Text.ToString(), out double resutl14))
			{
				if (TextBox_Sa2Power.Text.ToString().Contains(","))
				{
					TextBox_Sa2Power.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa2Temp.Text.ToString(), out double resutl15))
			{
				if (TextBox_Sa2Temp.Text.ToString().Contains(","))
				{
					TextBox_Sa2Temp.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa2Height.Text.ToString(), out double resutl16))
			{
				if (TextBox_Sa2Height.Text.ToString().Contains(","))
				{
					TextBox_Sa2Height.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa2Freq.Text.ToString(), out double resutl17))
			{
				if (TextBox_Sa2Freq.Text.ToString().Contains(","))
				{
					TextBox_Sa2Freq.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}


			if (!double.TryParse(TextBox_Sa3Power.Text.ToString(), out double resutl18))
			{
				if (TextBox_Sa3Power.Text.ToString().Contains(","))
				{
					TextBox_Sa3Power.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa3Temp.Text.ToString(), out double resutl19))
			{
				if (TextBox_Sa3Temp.Text.ToString().Contains(","))
				{
					TextBox_Sa3Temp.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa3Height.Text.ToString(), out double resutl20))
			{
				if (TextBox_Sa3Height.Text.ToString().Contains(","))
				{
					TextBox_Sa3Height.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa3Freq.Text.ToString(), out double resutl21))
			{
				if (TextBox_Sa3Freq.Text.ToString().Contains(","))
				{
					TextBox_Sa3Freq.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa4Power.Text.ToString(), out double resutl22))
			{
				if (TextBox_Sa4Power.Text.ToString().Contains(","))
				{
					TextBox_Sa4Power.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa4Temp.Text.ToString(), out double resutl23))
			{
				if (TextBox_Sa4Temp.Text.ToString().Contains(","))
				{
					TextBox_Sa4Temp.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}

				
			}

			if (!double.TryParse(TextBox_Sa4Height.Text.ToString(), out double resutl24))
			{
				if (TextBox_Sa4Height.Text.ToString().Contains(","))
				{
					TextBox_Sa4Height.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_Sa4Freq.Text.ToString(), out double resutl25))
			{
				if (TextBox_Sa4Freq.Text.ToString().Contains(","))
				{
					TextBox_Sa4Freq.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}



			if (!double.TryParse(TextBox_HfwLineSpeed.Text.ToString(), out double resutl26))
			{
				if (TextBox_HfwLineSpeed.Text.ToString().Contains(","))
				{
					TextBox_HfwLineSpeed.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_HfwPower.Text.ToString(), out double resutl27))
			{
				if (TextBox_HfwPower.Text.ToString().Contains(","))
				{
					TextBox_HfwPower.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_HfwFreq.Text.ToString(), out double resutl28))
			{
				if (TextBox_HfwFreq.Text.ToString().Contains(","))
				{
					TextBox_HfwFreq.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_HfwVeeX.Text.ToString(), out double resutl29))
			{
				if (TextBox_HfwVeeX.Text.ToString().Contains(","))
				{
					TextBox_HfwVeeX.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_SustCw1.Text.ToString(), out double resutl30))
			{
				if (TextBox_SustCw1.Text.ToString().Contains(","))
				{
					TextBox_SustCw1.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_SustCw2.Text.ToString(), out double resutl31))
			{
				if (TextBox_SustCw2.Text.ToString().Contains(","))
				{
					TextBox_SustCw2.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_StripWidthTarget.Text.ToString(), out double resutl32))
			{
				if (TextBox_StripWidthTarget.Text.ToString().Contains(","))
				{
					TextBox_StripWidthTarget.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_HfwMode.Text.ToString(), out double resutl33))
			{
				if (TextBox_HfwMode.Text.ToString().Contains(","))
				{
					TextBox_HfwMode.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_HfwpreHeatPower.Text.ToString(), out double resutl34))
			{
				if (TextBox_HfwpreHeatPower.Text.ToString().Contains(","))
				{
					TextBox_HfwpreHeatPower.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_HfwTemperature.Text.ToString(), out double resutl35))
			{
				if (TextBox_HfwTemperature.Text.ToString().Contains(","))
				{
					TextBox_HfwTemperature.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_HfwSpcGain.Text.ToString(), out double resutl36))
			{
				if (TextBox_HfwSpcGain.Text.ToString().Contains(","))
				{
					TextBox_HfwSpcGain.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}

			if (!double.TryParse(TextBox_HfwSpcSlop.Text.ToString(), out double resutl37))
			{
				if (TextBox_HfwSpcSlop.Text.ToString().Contains(","))
				{
					TextBox_HfwSpcSlop.Background = System.Windows.Media.Brushes.Pink;
					r = false;
				}
				
			}
			return r;

		}


		void ReflushTextBoxBackground()
        {
			TextBox_StripThickness.Background = System.Windows.Media.Brushes.White;

			TextBox_StripWidth.Background = System.Windows.Media.Brushes.White;

			TextBox_PipeOd.Background = System.Windows.Media.Brushes.White;

			TextBox_PipeThickness.Background = System.Windows.Media.Brushes.White;

			TextBox_YeildStrength.Background = System.Windows.Media.Brushes.White;

			TextBox_AccPressure1.Background = System.Windows.Media.Brushes.White;

			TextBox_AccPressure2.Background = System.Windows.Media.Brushes.White;

			TextBox_EmCuttingSpeed.Background = System.Windows.Media.Brushes.White;

			TextBox_EmChipload.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa1Power.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa1Temp.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa1Height.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa1Freq.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa2Power.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa2Temp.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa2Height.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa2Freq.Background = System.Windows.Media.Brushes.White;


			TextBox_Sa3Power.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa3Temp.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa3Height.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa3Freq.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa4Power.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa4Temp.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa4Height.Background = System.Windows.Media.Brushes.White;

			TextBox_Sa4Freq.Background = System.Windows.Media.Brushes.White;

			TextBox_HfwLineSpeed.Background = System.Windows.Media.Brushes.White;

			TextBox_HfwPower.Background = System.Windows.Media.Brushes.White;

			TextBox_HfwFreq.Background = System.Windows.Media.Brushes.White;

			TextBox_HfwVeeX.Background = System.Windows.Media.Brushes.White;

			TextBox_SustCw1.Background = System.Windows.Media.Brushes.White;

			TextBox_SustCw2.Background = System.Windows.Media.Brushes.White;

			TextBox_StripWidthTarget.Background = System.Windows.Media.Brushes.White;

			TextBox_HfwMode.Background = System.Windows.Media.Brushes.White;

			TextBox_HfwpreHeatPower.Background = System.Windows.Media.Brushes.White;

			TextBox_HfwTemperature.Background = System.Windows.Media.Brushes.White;

			TextBox_HfwSpcGain.Background = System.Windows.Media.Brushes.White;

			TextBox_HfwSpcSlop.Background = System.Windows.Media.Brushes.White;
		}


		/// <summary>
		/// delete recipeDetail
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_Delete_recipe_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				recipeDetailMode = "RecipeDetail";
				if (dataGrid_RecipeDetail.SelectedItem == null)
				{
					MessageBox.Show("Please select an  recipe");
					return;
				}
				else
				{
					var recipedrv = dataGrid_RecipeDetail.SelectedItem as DataRowView;
					if (recipedrv != null)
					{
						string recipeNo = recipedrv.Row[RECIPE_INFO.fd_recipeNo].ToString();
						if (MessageBox.Show("Are you sure you want to delete the recipe?", "DELETE", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
						{
							client.SendMessage(Identity.definedCommand, Identity.deleteRecipeByRecipe_id, recipeNo + ";" + USER_TABLE.user_Name);
						}
						return;
					}
				}
				LogHelper.WriteLog("btn_Delete_recipe_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_Delete_recipe_Click", ex);
			}

		}
		/// <summary>
		/// recipeDetail table data page up
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_UpPage_recipe_Click(object sender, RoutedEventArgs e)
		{
			if (recipeDetail_Index > 1)
			{
				recipeDetail_Index--;
				textBox_RecipePage.Text = recipeDetail_Index.ToString();
				if (recipeDetailPageSql == "")
				{
					recipeDetailPageSql = string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} order by {1} desc,{2} desc) a)",
				  RECIPE_INFO.tableName, RECIPE_INFO.fd_modifyDate, RECIPE_INFO.fd_createDate);
				}
				recipeDetailMode = "RecipeDetail";
				client.SendMessage(Identity.definedCommand, Identity.selectRecipeByParameters, recipeDetailPageSql + ";" + ((recipeDetail_Index - 1) * recipeDetail_Pagenum) + ";" + recipeDetail_Index * recipeDetail_Pagenum);
			}
			
		}
		/// <summary>
		/// recipeDetail table data page down
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_DownPage_recipe_Click(object sender, RoutedEventArgs e)
		{
			if (recipeDetail_index_isChange && Convert.ToInt32(textBox_RecipePage.Text) < Convert.ToInt32(textBox_RecipeTotalPages.Text))
			{
				recipeDetail_Index++;
				textBox_RecipePage.Text = recipeDetail_Index.ToString();
				if (recipeDetailPageSql == "")
				{
					recipeDetailPageSql = string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} order by {1} desc,{2} desc) a)",
				  RECIPE_INFO.tableName, RECIPE_INFO.fd_modifyDate, RECIPE_INFO.fd_createDate);
				}
				recipeDetailMode = "RecipeDetail";
				client.SendMessage(Identity.definedCommand, Identity.selectRecipeByParameters, recipeDetailPageSql + ";" + ((recipeDetail_Index - 1) * recipeDetail_Pagenum) + ";" + recipeDetail_Index * recipeDetail_Pagenum);
			}
		}
		#endregion

		#endregion

		#region BatchSampleRule handle
		#region Task Select BatchSampleRule
		/// <summary>
		/// Task Bind BatchSampleRule Select button
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_SelectBatchSampleRule_Click(object sender, RoutedEventArgs e)
		{
			batchSampleRuleDetailMode = "BatchSampleRuleBind";
			Popup_BatchSampleRule.IsOpen = true;
			//设置Popup的高度		
			DependencyObject parent = Popup_BatchSampleRule.Child;
			do
			{
				parent = VisualTreeHelper.GetParent(parent);
				if (parent != null && parent.ToString() == "System.Windows.Controls.Primitives.PopupRoot")
				{
					var element = parent as FrameworkElement;
					element.Height = 700;
					break;
				}
			}
			while (parent != null);
			textBox_BindBatchSampleRulePage.Text = batchSampleRuleBind_Index.ToString();
			client.SendMessage(Identity.definedCommand, Identity.select_BatchSampleRuleByIndex, ((batchSampleRuleBind_Index - 1) * batchSampleRuleBind_Pagenum) + ";" + batchSampleRuleBind_Index * batchSampleRuleBind_Pagenum);
		}
		/// <summary>
		/// PopupBatchSampleRule SelectionChanged
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_BindBatchSampleRule_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (dataGrid_BindBatchSampleRule.SelectedItem != null)
			{
				var batchSampleRuleDRV = dataGrid_BindBatchSampleRule.SelectedItem as DataRowView;
				textBox_BindBatchSampleRule.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_sampleNo].ToString();
				TextBox_BindBatcRule_sampleNo.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_sampleNo].ToString();
				TextBox_BindBatchRule_sampleName.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_sampleName].ToString();
				TextBox_BindBatchRule_CycleQuantity1.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_cycleQuanti1].ToString();
				TextBox_BindBatchRule_FltLength1.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_fltLength1].ToString();
				TextBox_BindBatchRule_MtLength1.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_mtLength1].ToString();
				TextBox_BindBatchRule_AtLength1.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_atLength1].ToString();
				TextBox_BindBatchRule_FltLength2.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_fltLength2].ToString();
				TextBox_BindBatchRule_MtLength2.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_mtLength2].ToString();
				TextBox_BindBatchRule_AtLength2.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_atLength2].ToString();
				TextBox_BindBatchRule_FltLength3.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_fltLength3].ToString();
				TextBox_BindBatchRule_MtLength3.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_mtLength3].ToString();
				TextBox_BindBatchRule_AtLength3.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_atLength3].ToString();
				TextBox_BindBatchRule_FltLength4.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_fltLength4].ToString();
				TextBox_BindBatchRule_MtLength4.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_mtLength4].ToString();
				TextBox_BindBatchRule_AtLength4.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_atLength4].ToString();
				TextBox_BindBatchRule_FltLength5.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_fltLength5].ToString();
				TextBox_BindBatchRule_MtLength5.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_mtLength5].ToString();
				TextBox_BindBatchRule_AtLength5.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_atLength5].ToString();
				TextBox_BindBatchRule_FltLength6.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_fltLength6].ToString();
				TextBox_BindBatchRule_MtLength6.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_mtLength6].ToString();
				TextBox_BindBatchRule_AtLength6.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_atLength6].ToString();
				TextBox_BindBatchRule_FltLength7.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_fltLength7].ToString();
				TextBox_BindBatchRule_MtLength7.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_mtLength7].ToString();
				TextBox_BindBatchRule_AtLength7.Text = batchSampleRuleDRV[BATCH_SAMPLE_RULE.fd_atLength7].ToString();
			}

		}
		/// <summary>
		/// confirm whether sampleno of batchsamplerule is imported into task 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_BindBatchSampleRule_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
		{
			if (MessageBox.Show("Are you sure you want to import BatchSampleNo into Task?", "IMPORT", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
			{
				if (dataGrid_BindBatchSampleRule.SelectedItem != null)
				{
					var batchSampleRuleBind = dataGrid_BindBatchSampleRule.SelectedItem as DataRowView;
					if (batchSampleRuleBind != null)
					{
						string SampleNo = batchSampleRuleBind.Row[BATCH_SAMPLE_RULE.fd_sampleNo].ToString();
						textBox_BatchSamRule.Text = SampleNo;						
					}
				}
			}
		}
		/// <summary>
		/// PopupBatchSampleRule page down
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_DownPage_BindBatchSampleRule_Click(object sender, RoutedEventArgs e)
		{
			if (batchSampleRuleBind_index_isChange && Convert.ToInt32(textBox_BindBatchSampleRulePage.Text) < Convert.ToInt32(textBox_BindBatchSampleRuleTotalPages.Text))
			{
				batchSampleRuleBind_Index++;
				textBox_BindBatchSampleRulePage.Text = batchSampleRuleBind_Index.ToString();
				batchSampleRuleDetailMode = "BatchSampleRuleBind";
				client.SendMessage(Identity.definedCommand, Identity.select_BatchSampleRuleByIndex, ((batchSampleRuleBind_Index - 1) * batchSampleRuleBind_Pagenum) + ";" + batchSampleRuleBind_Index * batchSampleRuleBind_Pagenum);
			}
		}
		/// <summary>
		/// PopupBatchSampleRule page up
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_UpPage_BindBatchSampleRule_Click(object sender, RoutedEventArgs e)
		{
			if (batchSampleRuleBind_Index > 1)
			{
				batchSampleRuleBind_Index--;
				textBox_BindBatchSampleRulePage.Text = batchSampleRuleBind_Index.ToString();
			}
			batchSampleRuleDetailMode = "BatchSampleRuleBind";
			client.SendMessage(Identity.definedCommand, Identity.select_BatchSampleRuleByIndex, ((batchSampleRuleBind_Index - 1) * batchSampleRuleBind_Pagenum) + ";" + batchSampleRuleBind_Index * batchSampleRuleBind_Pagenum);
		}
		/// <summary>
		/// close PopupBatchSampleRule
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_BatchSampleRule_Close_Click(object sender, RoutedEventArgs e)
		{
			Popup_BatchSampleRule.IsOpen = false;
		}
		#endregion

		#region BatchSampleRule Detail
		/// <summary>
		/// uncheck row information
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_BatchRuleDetail_MouseDown(object sender, MouseButtonEventArgs e)
		{
			dataGrid_BatchRuleDetail.SelectedItem = null;
		}
		/// <summary>
		/// BatchSampleRule selectionChanged
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_BatchRuleDetail_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			TextBox_BatchSampleNo.IsEnabled = false;
			StackPanel_Edit_BatchRule.IsEnabled = false;
			TextBox_BatchSampleName.IsEnabled = false;
			if (dataGrid_BatchRuleDetail.SelectedItem != null)
			{
				var batchRuleDetail = dataGrid_BatchRuleDetail.SelectedItem as DataRowView;
				if (batchRuleDetail != null)
				{
					string sampleNo = batchRuleDetail.Row[BATCH_SAMPLE_RULE.fd_sampleNo].ToString();					
					TextBox_BatchSampleNo.Text = sampleNo;
					TextBox_BatchSampleName.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_sampleName].ToString();
					TextBox_CycleQuantity1.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_cycleQuanti1].ToString();
					TextBox_FltLength1.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_fltLength1].ToString();
					TextBox_MtLength1.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_mtLength1].ToString();
					TextBox_AtLength1.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_atLength1].ToString();
					TextBox_FltLength2.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_fltLength2].ToString();
					TextBox_MtLength2.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_mtLength2].ToString();
					TextBox_AtLength2.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_atLength2].ToString();
					TextBox_FltLength3.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_fltLength3].ToString();
					TextBox_MtLength3.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_mtLength3].ToString();
					TextBox_AtLength3.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_atLength3].ToString();
					TextBox_FltLength4.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_fltLength4].ToString();
					TextBox_MtLength4.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_mtLength4].ToString();
					TextBox_AtLength4.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_atLength4].ToString();
					TextBox_FltLength5.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_fltLength5].ToString();
					TextBox_MtLength5.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_mtLength5].ToString();
					TextBox_AtLength5.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_atLength5].ToString();
					TextBox_FltLength6.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_fltLength6].ToString();
					TextBox_MtLength6.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_mtLength6].ToString();
					TextBox_AtLength6.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_atLength6].ToString();
					TextBox_FltLength7.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_fltLength7].ToString();
					TextBox_MtLength7.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_mtLength7].ToString();
					TextBox_AtLength7.Text = batchRuleDetail[BATCH_SAMPLE_RULE.fd_atLength7].ToString();
				}
			}
		}
		/// <summary>
		/// new BatchSampleRule
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_New_BatchRule_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (MessageBox.Show("Once created, it cannot be deleted. Are you sure you want to create a new BatchSampleRule?", "New", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.Cancel)
				{
					return;
				}
				StackPanel_Edit_BatchRule.IsEnabled = true;
				TextBox_BatchSampleNo.IsEnabled = true;
				TextBox_BatchSampleName.IsEnabled = true;
				var batchDRV = dataGrid_BatchRuleDetail.SelectedItem as DataRowView;
				if (dataGrid_BatchRuleDetail.SelectedItem == null)
				{
					TextBox_BatchSampleNo.Text = "";
					TextBox_BatchSampleName.Text = "";
					TextBox_CycleQuantity1.Text = "";
					TextBox_FltLength1.Text = "";
					TextBox_MtLength1.Text = "";
					TextBox_AtLength1.Text = "";
					TextBox_FltLength2.Text = "";
					TextBox_MtLength2.Text = "";
					TextBox_AtLength2.Text = "";
					TextBox_FltLength3.Text = "";
					TextBox_MtLength3.Text = "";
					TextBox_AtLength3.Text = "";
					TextBox_FltLength4.Text = "";
					TextBox_MtLength4.Text = "";
					TextBox_AtLength4.Text = "";
					TextBox_FltLength5.Text = "";
					TextBox_MtLength5.Text = "";
					TextBox_AtLength5.Text = "";
					TextBox_FltLength6.Text = "";
					TextBox_MtLength6.Text = "";
					TextBox_AtLength6.Text = "";
					TextBox_FltLength7.Text = "";
					TextBox_MtLength7.Text = "";
					TextBox_AtLength7.Text = "";
				}
				else
				{
					TextBox_BatchSampleNo.Text = "";
				}
				buttonSaveBatchRule_EditorNew = "New";
				LogHelper.WriteLog("btn_New_BatchRule_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_New_BatchRule_Click", ex);
			}
		}
		/// <summary>
		/// edit BatchSampleRule
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_Edit_BatchRule_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				TextBox_BatchSampleNo.IsEnabled = false;
				StackPanel_Edit_BatchRule.IsEnabled = true;				
				TextBox_BatchSampleName.IsEnabled = true;
				buttonSaveBatchRule_EditorNew = "Edit";
				LogHelper.WriteLog("btn_Edit_BatchRule_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_Edit_BatchRule_Click", ex);
			}

		}
		/// <summary>
		/// save BatchSampleRule information
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_Save_BatchRule_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (TextBox_BatchSampleNo.Text.ToString() == "")
				{
					MessageBox.Show("Sample No can not be null");
					return;
				}
				if (TextBox_BatchSampleName.Text.ToString() == "")
				{
					MessageBox.Show("Sample name can not be null");
					return;
				}
				DataTable dataTableBatchRule = new DataTable();
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_sampleName, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_sampleNo, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_cycleQuanti1, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_fltLength1, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_mtLength1, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_atLength1, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_fltLength2, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_mtLength2, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_atLength2, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_fltLength3, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_mtLength3, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_atLength3, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_fltLength4, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_mtLength4, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_atLength4, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_fltLength5, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_mtLength5, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_atLength5, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_fltLength6, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_mtLength6, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_atLength6, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_fltLength7, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_mtLength7, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_atLength7, typeof(string));
				dataTableBatchRule.Columns.Add(BATCH_SAMPLE_RULE.fd_updateTime, typeof(string));

				dataTableBatchRule.Rows.Add(TextBox_BatchSampleName.Text.ToString(), TextBox_BatchSampleNo.Text.ToString(), TextBox_CycleQuantity1.Text.ToString(), TextBox_FltLength1.Text.ToString(), TextBox_MtLength1.Text.ToString(), TextBox_AtLength1.Text.ToString(), TextBox_FltLength2.Text.ToString(), TextBox_MtLength2.Text.ToString(),
					TextBox_AtLength2.Text.ToString(), TextBox_FltLength3.Text.ToString(), TextBox_MtLength3.Text.ToString(), TextBox_AtLength3.Text.ToString(), TextBox_FltLength4.Text.ToString(), TextBox_MtLength4.Text.ToString(), TextBox_AtLength4.Text.ToString(), TextBox_FltLength5.Text.ToString(), TextBox_MtLength5.Text.ToString(), TextBox_AtLength5.Text.ToString(),
					TextBox_FltLength6.Text.ToString(), TextBox_MtLength6.Text.ToString(), TextBox_AtLength6.Text.ToString(), TextBox_FltLength7.Text.ToString(), TextBox_MtLength7.Text.ToString(), TextBox_AtLength7.Text.ToString(), "");

				string jsonBatchRule = "";
				if (MessageBox.Show("Are you sure you want to save the Batch Rule?", "EDIT", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
				{
					if (buttonSaveBatchRule_EditorNew == "New")
					{
						batchSampleRuleDetailMode = "BatchSampleRuleDetail";
						dataTableBatchRule.Rows[0][BATCH_SAMPLE_RULE.fd_updateTime] = DateTime.Now.ToString(Formats.GetDateFormat());
						jsonBatchRule = JsonHelper.SerializeObject(dataTableBatchRule);
						client.SendMessage(Identity.definedCommand, Identity.insert_BatchSampleRule, jsonBatchRule);
					}
					else if (buttonSaveBatchRule_EditorNew == "Edit")
					{
						batchSampleRuleDetailMode = "BatchSampleRuleDetail";
						dataTableBatchRule.Rows[0][BATCH_SAMPLE_RULE.fd_updateTime] = DateTime.Now.ToString(Formats.GetDateFormat());
						jsonBatchRule = JsonHelper.SerializeObject(dataTableBatchRule);
						client.SendMessage(Identity.definedCommand, Identity.edit_BatchSampleRule, jsonBatchRule);
					}
				}
				LogHelper.WriteLog("btn_Save_BatchRule_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_Save_BatchRule_Click", ex);
			}

		}
		/// <summary>
		/// delete BatchSampleRule table data
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_Delete_BatchRule_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (Privilege.IsPrivilege(USER_TABLE.user_Level, btn_Delete_BatchRule.Tag.ToString()))
				{
					if (dataGrid_BatchRuleDetail.SelectedItem == null)
					{
						MessageBox.Show("Please select an  batch sample rule");
						return;
					}
					else
					{
						var batchruledrv = dataGrid_BatchRuleDetail.SelectedItem as DataRowView;
						if (batchruledrv != null)
						{
							string sampleNo = batchruledrv.Row[BATCH_SAMPLE_RULE.fd_sampleNo].ToString();
							if (MessageBox.Show("Are you sure you want to delete the batch sample rule?", "DELETE", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
							{
								client.SendMessage(Identity.definedCommand, Identity.delete_BatchSampleRule, sampleNo);
							}
							return;
						}
					}
				}
				else
				{
					MessageBox.Show("You do not have the permission");
				}
				LogHelper.WriteLog("btn_Delete_BatchRule_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_Delete_BatchRule_Click", ex);
			}

		}
		/// <summary>
		/// BatchSampleRule page up
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_UpPage_BatchRule_Click(object sender, RoutedEventArgs e)
		{
			if (batchSampleRuleDetail_Index > 1)
			{
				batchSampleRuleDetail_Index--;
				textBox_BatchSampleRulePage.Text = batchSampleRuleDetail_Index.ToString();
				batchSampleRuleDetailMode = "BatchSampleRuleDetail";
				client.SendMessage(Identity.definedCommand, Identity.select_BatchSampleRuleByIndex, ((batchSampleRuleDetail_Index - 1) * batchSampleRuleDetail_Pagenum) + ";" + batchSampleRuleDetail_Index * batchSampleRuleDetail_Pagenum);
			}			
		}
		/// <summary>
		/// BatchSampleRule page down
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_DownPage_BatchRule_Click(object sender, RoutedEventArgs e)
		{
			if (batchSampleRuleDetail_index_isChange && Convert.ToInt32(textBox_BatchSampleRulePage.Text) < Convert.ToInt32(textBox_BatchSampleRuleTotalPages.Text))
			{
				batchSampleRuleDetail_Index++;
				textBox_BatchSampleRulePage.Text = batchSampleRuleDetail_Index.ToString();
				batchSampleRuleDetailMode = "BatchSampleRuleDetail";
				client.SendMessage(Identity.definedCommand, Identity.select_BatchSampleRuleByIndex, ((batchSampleRuleDetail_Index - 1) * batchSampleRuleDetail_Pagenum) + ";" + batchSampleRuleDetail_Index * batchSampleRuleDetail_Pagenum);
			}
		}
		#endregion
		#endregion

		#region StripSampleRule handle
		#region Task Select StripSampleRule
		/// <summary>
		/// Task Bind StripSampleRule Select button
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_SelectStripSampleRule_Click(object sender, RoutedEventArgs e)
		{
			stripSampleRuleDetailMode = "StripSampleRuleBind";
			Popup_StripSampleRule.IsOpen = true;
			//设置Popup的高度		
			DependencyObject parent = Popup_StripSampleRule.Child;
			do
			{
				parent = VisualTreeHelper.GetParent(parent);
				if (parent != null && parent.ToString() == "System.Windows.Controls.Primitives.PopupRoot")
				{
					var element = parent as FrameworkElement;
					element.Height = 640;
					break;
				}
			}
			while (parent != null);
			textBox_BindStripSampleRulePage.Text = stripSampleRuleBind_Index.ToString();
			client.SendMessage(Identity.definedCommand, Identity.select_StripSampleRuleByIndex, ((stripSampleRuleBind_Index - 1) * stripSampleRuleBind_Pagenum) + ";" + stripSampleRuleBind_Index * stripSampleRuleBind_Pagenum);
		}
		/// <summary>
		/// PopupStripSampleRule SelectionChanged
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_BindStripSampleRule_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (dataGrid_BindStripSampleRule.SelectedItem != null)
			{
				var stripSampleRuleDRV = dataGrid_BindStripSampleRule.SelectedItem as DataRowView;
				textBox_BindStripSampleRule.Text = stripSampleRuleDRV[STRIP_SAMPLE_RULE.fd_sampleNo].ToString();
				TextBox_BindStripRule_sampleNo.Text = stripSampleRuleDRV[STRIP_SAMPLE_RULE.fd_sampleNo].ToString();
				TextBox_BindStripRule_sampleName.Text = stripSampleRuleDRV[STRIP_SAMPLE_RULE.fd_sampleName].ToString();
				TextBox_BindStripRule_FltFrontLength.Text = stripSampleRuleDRV[STRIP_SAMPLE_RULE.fd_fltFrontLength].ToString();
				TextBox_BindStripRule_MtFrontLength.Text = stripSampleRuleDRV[STRIP_SAMPLE_RULE.fd_mtFrontLength].ToString();
				TextBox_BindStripRule_AtFrontLength.Text = stripSampleRuleDRV[STRIP_SAMPLE_RULE.fd_atFrontLength].ToString();
				TextBox_BindStripRule_FltMiddleLength.Text = stripSampleRuleDRV[STRIP_SAMPLE_RULE.fd_fltMiddleLength].ToString();
				TextBox_BindStripRule_MtMiddleLength.Text = stripSampleRuleDRV[STRIP_SAMPLE_RULE.fd_mtMiddleLength].ToString();
				TextBox_BindStripRule_AtMiddleLength.Text = stripSampleRuleDRV[STRIP_SAMPLE_RULE.fd_atMiddleLength].ToString();
				TextBox_BindStripRule_FltEndLength.Text = stripSampleRuleDRV[STRIP_SAMPLE_RULE.fd_fltEndLength].ToString();
				TextBox_BindStripRule_MtEndLength.Text = stripSampleRuleDRV[STRIP_SAMPLE_RULE.fd_mtEndLength].ToString();
				TextBox_BindStripRule_AtEndLength.Text = stripSampleRuleDRV[STRIP_SAMPLE_RULE.fd_atEndLength].ToString();				
			}
		}
		/// <summary>
		/// confirm whether sampleno is imported into task
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_BindStripSampleRule_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
		{
			if (MessageBox.Show("Are you sure you want to import StripSampleNo into Task?", "IMPORT", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
			{
				if (dataGrid_BindStripSampleRule.SelectedItem != null)
				{
					var stripSampleRuleBind = dataGrid_BindStripSampleRule.SelectedItem as DataRowView;
					if (stripSampleRuleBind != null)
					{
						string SampleNo = stripSampleRuleBind.Row[STRIP_SAMPLE_RULE.fd_sampleNo].ToString();
						textBox_StripSamRule.Text = SampleNo;
					}
				}
			}
		}
		/// <summary>
		/// PopupStripSampleRule page up
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_UpPage_BindStripSampleRule_Click(object sender, RoutedEventArgs e)
		{
			if (stripSampleRuleBind_Index > 1)
			{
				stripSampleRuleBind_Index--;
				textBox_BindStripSampleRulePage.Text = stripSampleRuleBind_Index.ToString();
			}
			stripSampleRuleDetailMode = "StripSampleRuleBind";
			client.SendMessage(Identity.definedCommand, Identity.select_StripSampleRuleByIndex, ((stripSampleRuleBind_Index - 1) * stripSampleRuleBind_Pagenum) + ";" + stripSampleRuleBind_Index * stripSampleRuleBind_Pagenum);
		}
		/// <summary>
		/// PopupStripSampleRule page down
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_DownPage_BindStripSampleRule_Click(object sender, RoutedEventArgs e)
		{
			if (stripSampleRuleBind_index_isChange && Convert.ToInt32(textBox_BindStripSampleRulePage.Text) < Convert.ToInt32(textBox_BindStripSampleRuleTotalPages.Text))
			{
				stripSampleRuleBind_Index++;
				textBox_BindStripSampleRulePage.Text = stripSampleRuleBind_Index.ToString();
				stripSampleRuleDetailMode = "StripSampleRuleBind";
				client.SendMessage(Identity.definedCommand, Identity.select_StripSampleRuleByIndex, ((stripSampleRuleBind_Index - 1) * stripSampleRuleBind_Pagenum) + ";" + stripSampleRuleBind_Index * stripSampleRuleBind_Pagenum);
			}
		}
		/// <summary>
		/// close PopupBatchSampleRule
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_StripSampleRule_Close_Click(object sender, RoutedEventArgs e)
		{
			Popup_StripSampleRule.IsOpen = false;
		}
		#endregion

		#region StripSampleRule Detail
		/// <summary>
		/// uncheck row information
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_StripRuleDetail_MouseDown(object sender, MouseButtonEventArgs e)
		{
			dataGrid_StripRuleDetail.SelectedItem = null;
		}
		/// <summary>
		/// StripSampleRule selectionChanged
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void dataGrid_StripRuleDetail_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			TextBox_StripSampleNo.IsEnabled = false;
			StackPanel_Edit_StripRule.IsEnabled = false;
			if (dataGrid_StripRuleDetail.SelectedItem != null)
			{
				var stripDRV= dataGrid_StripRuleDetail.SelectedItem as DataRowView;
				if (stripDRV != null)
				{
					string sampleNo = stripDRV[STRIP_SAMPLE_RULE.fd_sampleNo].ToString();					
					TextBox_StripSampleNo.Text = sampleNo;
					TextBox_StripSampleName.Text = stripDRV[STRIP_SAMPLE_RULE.fd_sampleName].ToString();
					TextBox_FltFrontLength.Text = stripDRV[STRIP_SAMPLE_RULE.fd_fltFrontLength].ToString();
					TextBox_MtFrontLength.Text = stripDRV[STRIP_SAMPLE_RULE.fd_mtFrontLength].ToString();
					TextBox_AtFrontLength.Text = stripDRV[STRIP_SAMPLE_RULE.fd_atFrontLength].ToString();
					TextBox_FltMiddleLength.Text = stripDRV[STRIP_SAMPLE_RULE.fd_fltMiddleLength].ToString();
					TextBox_MtMiddleLength.Text = stripDRV[STRIP_SAMPLE_RULE.fd_fltMiddleLength].ToString();
					TextBox_AtMiddleLength.Text = stripDRV[STRIP_SAMPLE_RULE.fd_atMiddleLength].ToString();
					TextBox_FltEndLength.Text = stripDRV[STRIP_SAMPLE_RULE.fd_fltEndLength].ToString();
					TextBox_MtEndLength.Text = stripDRV[STRIP_SAMPLE_RULE.fd_mtEndLength].ToString();
					TextBox_AtEndLength.Text = stripDRV[STRIP_SAMPLE_RULE.fd_atEndLength].ToString();

				}
			}
		}
		/// <summary>
		/// new StripSampleRule
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_New_StripRule_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (MessageBox.Show("Once created, it cannot be deleted. Are you sure you want to create a new StripSampleRule?", "New", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.Cancel)
				{
					return;
				}
				StackPanel_Edit_StripRule.IsEnabled = true;
				TextBox_StripSampleNo.IsEnabled = true;
				var stripDRV = dataGrid_StripRuleDetail.SelectedItem as DataRowView;
				if (dataGrid_StripRuleDetail.SelectedItem == null)
				{
					TextBox_StripSampleNo.Text = "";
					TextBox_StripSampleName.Text = "";
					TextBox_FltFrontLength.Text = "";
					TextBox_MtFrontLength.Text = "";
					TextBox_AtFrontLength.Text = "";
					TextBox_FltMiddleLength.Text = "";
					TextBox_MtMiddleLength.Text = "";
					TextBox_AtMiddleLength.Text = "";
					TextBox_FltEndLength.Text = "";
					TextBox_MtEndLength.Text = "";
					TextBox_AtEndLength.Text = "";
				}
				else
				{
					TextBox_StripSampleNo.Text = "";
				}

				buttonSaveStripRule_EditorNew = "New";
				LogHelper.WriteLog("btn_New_StripRule_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_New_StripRule_Click", ex);
			}

		}
		/// <summary>
		/// edit StripSampleRule
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_Edit_StripRule_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				StackPanel_Edit_StripRule.IsEnabled = true;
				buttonSaveStripRule_EditorNew = "Edit";
				LogHelper.WriteLog("btn_Edit_StripRule_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_Edit_StripRule_Click", ex);
			}

		}
		/// <summary>
		/// save StripSampleRule
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_Save_StripRule_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (TextBox_StripSampleNo.Text.ToString() == "")
				{
					MessageBox.Show("Sample No can not be null");
					return;
				}
				if (TextBox_StripSampleName.Text.ToString() == "")
				{
					MessageBox.Show("Sample name can not be null");
					return;
				}
				DataTable dataTableStripRule = new DataTable();
				dataTableStripRule.Columns.Add(STRIP_SAMPLE_RULE.fd_sampleName, typeof(string));
				dataTableStripRule.Columns.Add(STRIP_SAMPLE_RULE.fd_sampleNo, typeof(string));
				dataTableStripRule.Columns.Add(STRIP_SAMPLE_RULE.fd_fltFrontLength, typeof(string));
				dataTableStripRule.Columns.Add(STRIP_SAMPLE_RULE.fd_mtFrontLength, typeof(string));
				dataTableStripRule.Columns.Add(STRIP_SAMPLE_RULE.fd_atFrontLength, typeof(string));
				dataTableStripRule.Columns.Add(STRIP_SAMPLE_RULE.fd_fltMiddleLength, typeof(string));
				dataTableStripRule.Columns.Add(STRIP_SAMPLE_RULE.fd_mtMiddleLength, typeof(string));
				dataTableStripRule.Columns.Add(STRIP_SAMPLE_RULE.fd_atMiddleLength, typeof(string));
				dataTableStripRule.Columns.Add(STRIP_SAMPLE_RULE.fd_fltEndLength, typeof(string));
				dataTableStripRule.Columns.Add(STRIP_SAMPLE_RULE.fd_mtEndLength, typeof(string));
				dataTableStripRule.Columns.Add(STRIP_SAMPLE_RULE.fd_atEndLength, typeof(string));
				dataTableStripRule.Columns.Add(STRIP_SAMPLE_RULE.fd_updateTime, typeof(string));

				dataTableStripRule.Rows.Add(TextBox_StripSampleName.Text.ToString(), TextBox_StripSampleNo.Text.ToString(), TextBox_FltFrontLength.Text.ToString(), TextBox_MtFrontLength.Text.ToString(), TextBox_AtFrontLength.Text.ToString(), TextBox_FltMiddleLength.Text.ToString(), TextBox_MtMiddleLength.Text.ToString(), TextBox_AtMiddleLength.Text.ToString(),
					TextBox_FltEndLength.Text.ToString(), TextBox_MtEndLength.Text.ToString(), TextBox_AtEndLength.Text.ToString());

				string jsonStripRule = "";
				if (MessageBox.Show("Are you sure you want to save the Strip Rule?", "EDIT", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
				{
					if (buttonSaveStripRule_EditorNew == "New")
					{
						stripSampleRuleDetailMode = "StripSampleRuleDetail";
						dataTableStripRule.Rows[0][STRIP_SAMPLE_RULE.fd_updateTime] = DateTime.Now.ToString(Formats.GetDateFormat());
						jsonStripRule = JsonHelper.SerializeObject(dataTableStripRule);
						client.SendMessage(Identity.definedCommand, Identity.insert_StripSampleRule, jsonStripRule);
					}
					else if (buttonSaveStripRule_EditorNew == "Edit")
					{
						stripSampleRuleDetailMode = "StripSampleRuleDetail";
						dataTableStripRule.Rows[0][STRIP_SAMPLE_RULE.fd_updateTime] = DateTime.Now.ToString(Formats.GetDateFormat());
						jsonStripRule = JsonHelper.SerializeObject(dataTableStripRule);
						client.SendMessage(Identity.definedCommand, Identity.edit_StripSampleRule, jsonStripRule);
					}
				}
				LogHelper.WriteLog("btn_Save_StripRule_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_Save_StripRule_Click", ex);
			}

		}
		/// <summary>
		/// delete StripSampleRule
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_Delete_StripRule_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (dataGrid_StripRuleDetail.SelectedItem == null)
				{
					MessageBox.Show("Please select an  strip sample rule");
					return;
				}
				else
				{
					var stripruledrv = dataGrid_StripRuleDetail.SelectedItem as DataRowView;
					if (stripruledrv != null)
					{
						string sampleNo = stripruledrv.Row[STRIP_SAMPLE_RULE.fd_sampleNo].ToString();
						if (MessageBox.Show("Are you sure you want to delete the strip sample rule?", "DELETE", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
						{
							client.SendMessage(Identity.definedCommand, Identity.delete_StripSampleRule, sampleNo);
						}
						return;
					}
				}
				LogHelper.WriteLog("btn_Delete_StripRule_Click");
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_Delete_StripRule_Click", ex);
			}

		}
		/// <summary>
		/// StripSampleRule page up
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_UpPage_StripRule_Click(object sender, RoutedEventArgs e)
		{
			if (stripSampleRuleDetail_Index > 1)
			{
				stripSampleRuleDetail_Index--;
				textBox_StripSampleRulePage.Text = stripSampleRuleDetail_Index.ToString();
				stripSampleRuleDetailMode = "StripSampleRuleDetail";
				client.SendMessage(Identity.definedCommand, Identity.select_StripSampleRuleByIndex, ((stripSampleRuleDetail_Index - 1) * stripSampleRuleDetail_Pagenum) + ";" + stripSampleRuleDetail_Index * stripSampleRuleDetail_Pagenum);
			}
			
		}
		/// <summary>
		/// StripSampleRule page down
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_DownPage_StripRule_Click(object sender, RoutedEventArgs e)
		{
			if (stripSampleRuleDetail_index_isChange && Convert.ToInt32(textBox_StripSampleRulePage.Text) < Convert.ToInt32(textBox_StripSampleRuleTotalPages.Text))
			{
				stripSampleRuleDetail_Index++;
				textBox_StripSampleRulePage.Text = stripSampleRuleDetail_Index.ToString();
				stripSampleRuleDetailMode = "StripSampleRuleDetail";
				client.SendMessage(Identity.definedCommand, Identity.select_StripSampleRuleByIndex, ((stripSampleRuleDetail_Index - 1) * stripSampleRuleDetail_Pagenum) + ";" + stripSampleRuleDetail_Index * stripSampleRuleDetail_Pagenum);
			}
		}
		#endregion
		#endregion

		#region Production Standard
		/// <summary>
		/// refresh Production Standard table data
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_StandardSelect_Click(object sender, RoutedEventArgs e)
		{
			client.SendMessage(Identity.definedCommand, Identity.selectProductionStandard, "");
		}
		/// <summary>
		/// new Production Standard
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_NewStandard_Click(object sender, RoutedEventArgs e)
		{
			Popup_ProductionStadard.IsOpen = true;
			btnSaveProStandard = "New";
			textBox_Popup_StandardCode.IsEnabled = true;
			textBox_Popup_StandardCode.Text = "";
			textBox_Popup_StandardName.Text = "";
		}
		/// <summary>
		/// edit Production Standard
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_StandardEdit_Click(object sender, RoutedEventArgs e)
		{
			Popup_ProductionStadard.IsOpen = true;
			try
			{
				if (dataGrid_ProductionStandard.SelectedItem != null)
				{
					var productionStandard = dataGrid_ProductionStandard.SelectedItem as DataRowView;
					textBox_Popup_StandardCode.IsEnabled = false;
					textBox_Popup_StandardCode.Text = productionStandard[PRODUCTION_STANDARD.fd_standardNo].ToString();
					textBox_Popup_StandardName.Text = productionStandard[PRODUCTION_STANDARD.fd_standardName].ToString();
				}
				btnSaveProStandard = "Edit";
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_StandardEdit_Click", ex);
			}						
		}
		/// <summary>
		/// save ProductionStandard
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_SaveProductionStandard_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (textBox_Popup_StandardCode.Text == "" || textBox_Popup_StandardName.Text == "")
				{
					MessageBox.Show("Input box cannot be empty");
					return;
				}
				//判断ProductionStandard是否存在
				if (dictionaryProStandard.ContainsKey(textBox_Popup_StandardName.Text.ToString()))
				{
					MessageBox.Show("Standard Name already exists, please re-enter");
					return;
				}				

				if (btnSaveProStandard == "New")
				{
					//判断ProductionStandard是否存在
					if (dictionaryProStandard.ContainsKey(textBox_Popup_StandardCode.Text.ToString()))
					{
						MessageBox.Show("Standard Code already exists, please re-enter");
						return;
					}
					client.SendMessage(Identity.definedCommand, Identity.insert_ProductionStandard, textBox_Popup_StandardCode.Text+";"+ textBox_Popup_StandardName.Text);
				}
				else if (btnSaveProStandard == "Edit")
				{
					client.SendMessage(Identity.definedCommand, Identity.edit_ProductionStandard, textBox_Popup_StandardCode.Text + ";" + textBox_Popup_StandardName.Text);
				}
			}
			catch (Exception ex)
			{
				LogHelper.WriteLog("btn_SaveProductionStandard_Click", ex);
			}
		}
		/// <summary>
		/// close ProductionStandard
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btn_CloseProductionStandard_Click(object sender, RoutedEventArgs e)
		{
			Popup_ProductionStadard.IsOpen = false;
		}
		#endregion

		#region Popup_Task Dragable
		bool isDownPopup_Task;
		System.Windows.Point originalPointPopup_Task;

		public System.Windows.Point OriginalPointPopup_Task { get => originalPointPopup_Task; set => originalPointPopup_Task = value; }
		public bool IsDownPopup_Task { get => isDownPopup_Task; set => isDownPopup_Task = value; }
		private void btn_Popup_Task_ChangePosition_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			IsDownPopup_Task = true;
			OriginalPointPopup_Task = e.GetPosition(Popup_Task);
		}

		private void btn_Popup_Task_ChangePosition_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			IsDownPopup_Task = false;
		}

		private void btn_Popup_Task_ChangePosition_PreviewMouseMove(object sender, MouseEventArgs e)
		{
			if (IsDownPopup_Task)
			{
				System.Windows.Point pos = e.GetPosition(Popup_Task);
				Popup_Task.HorizontalOffset += pos.X - OriginalPointPopup_Task.X;
				Popup_Task.VerticalOffset += pos.Y - OriginalPointPopup_Task.Y;
				OriginalPointPopup_Task = pos;
			}
		}

		#endregion
		#region  Popup_Strip Dragable
		bool isDownPopup_Strip;
		System.Windows.Point originalPointPopup_Strip;

		public System.Windows.Point OriginalPointPopup_Strip { get => originalPointPopup_Strip; set => originalPointPopup_Strip = value; }
		public bool IsDownPopup_Strip { get => isDownPopup_Strip; set => isDownPopup_Strip = value; }

		private void btn_Popup_Strip_ChangePosition_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			IsDownPopup_Strip = true;
			OriginalPointPopup_Strip = e.GetPosition(Popup_Strip);
		}

		private void btn_Popup_Strip_ChangePosition_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			IsDownPopup_Strip = false;
		}

		private void btn_Popup_Strip_ChangePosition_PreviewMouseMove(object sender, MouseEventArgs e)
		{
			if (IsDownPopup_Strip)
			{
				System.Windows.Point pos = e.GetPosition(Popup_Strip);
				Popup_Strip.HorizontalOffset += pos.X - OriginalPointPopup_Strip.X;
				Popup_Strip.VerticalOffset += pos.Y - OriginalPointPopup_Strip.Y;
				OriginalPointPopup_Strip = pos;
			}
		}
		#endregion
		#region Popup_Recipe Dragable
		bool isDownPopup_Recipe;
		System.Windows.Point originalPointPopup_Recipe;

		public System.Windows.Point OriginalPointPopup_Recipe { get => originalPointPopup_Recipe; set => originalPointPopup_Recipe = value; }
		public bool IsDownPopup_Recipe { get => isDownPopup_Recipe; set => isDownPopup_Recipe = value; }
		private void btn_Popup_Recipe_ChangePosition_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			IsDownPopup_Recipe = false;
		}

		private void btn_Popup_Recipe_ChangePosition_PreviewMouseMove(object sender, MouseEventArgs e)
		{
			if (IsDownPopup_Recipe)
			{
				System.Windows.Point pos = e.GetPosition(Popup_Recipe);
				Popup_Recipe.HorizontalOffset += pos.X - OriginalPointPopup_Recipe.X;
				Popup_Recipe.VerticalOffset += pos.Y - OriginalPointPopup_Recipe.Y;
				OriginalPointPopup_Recipe = pos;
			}
		}

		private void btn_Popup_Recipe_ChangePosition_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			IsDownPopup_Recipe = true;
			OriginalPointPopup_Recipe = e.GetPosition(Popup_Recipe);
		}


		#endregion
		#region Popup_BatchSampleRule Dragable
		bool isDownPopup_BatchSampleRule;
		System.Windows.Point originalPointPopup_BatchSampleRule;

		public System.Windows.Point OriginalPointPopup_BatchSampleRule { get => originalPointPopup_BatchSampleRule; set => originalPointPopup_BatchSampleRule = value; }
		public bool IsDownPopup_BatchSampleRule { get => isDownPopup_BatchSampleRule; set => isDownPopup_BatchSampleRule = value; }
		private void btn_Popup_BatchSampleRule_ChangePosition_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			IsDownPopup_BatchSampleRule = true;
			OriginalPointPopup_BatchSampleRule = e.GetPosition(Popup_BatchSampleRule);
		}

		private void btn_Popup_BatchSampleRule_ChangePosition_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			IsDownPopup_BatchSampleRule = false;
		}

		private void btn_Popup_BatchSampleRule_ChangePosition_PreviewMouseMove(object sender, MouseEventArgs e)
		{
			if (IsDownPopup_BatchSampleRule)
			{
				System.Windows.Point pos = e.GetPosition(Popup_BatchSampleRule);
				Popup_BatchSampleRule.HorizontalOffset += pos.X - OriginalPointPopup_BatchSampleRule.X;
				Popup_BatchSampleRule.VerticalOffset += pos.Y - OriginalPointPopup_BatchSampleRule.Y;
				OriginalPointPopup_BatchSampleRule = pos;
			}
		}
		#endregion
		#region Popup_StripSampleRule Dragable
		bool isDownPopup_StripSampleRule;
		System.Windows.Point originalPointPopup_StripSampleRule;

		public System.Windows.Point OriginalPointPopup_StripSampleRule { get => originalPointPopup_StripSampleRule; set => originalPointPopup_StripSampleRule = value; }
		public bool IsDownPopup_StripSampleRule { get => isDownPopup_StripSampleRule; set => isDownPopup_StripSampleRule = value; }
		private void btn_Popup_StripSampleRule_ChangePosition_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			IsDownPopup_StripSampleRule = true;
			OriginalPointPopup_StripSampleRule = e.GetPosition(Popup_StripSampleRule);
		}

		private void btn_Popup_StripSampleRule_ChangePosition_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			IsDownPopup_StripSampleRule = false;
		}

		private void btn_Popup_StripSampleRule_ChangePosition_PreviewMouseMove(object sender, MouseEventArgs e)
		{
			if (IsDownPopup_StripSampleRule)
			{
				System.Windows.Point pos = e.GetPosition(Popup_StripSampleRule);
				Popup_StripSampleRule.HorizontalOffset += pos.X - OriginalPointPopup_StripSampleRule.X;
				Popup_StripSampleRule.VerticalOffset += pos.Y - OriginalPointPopup_StripSampleRule.Y;
				OriginalPointPopup_StripSampleRule = pos;
			}
		}
		#endregion
		#region Popup_ProductionStandard Dragable
		bool isDownPopup_ProductionStandard;
		System.Windows.Point originalPointPopup_ProductionStandard;

		public System.Windows.Point OriginalPointPopup_ProductionStandard { get => originalPointPopup_ProductionStandard; set => originalPointPopup_ProductionStandard = value; }
		public bool IsDownPopup_ProductionStandard { get => isDownPopup_ProductionStandard; set => isDownPopup_ProductionStandard = value; }
		private void btn_Popup_ProductionStadard_ChangePosition_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			IsDownPopup_ProductionStandard = true;
			OriginalPointPopup_ProductionStandard = e.GetPosition(Popup_ProductionStadard);
		}

		private void btn_Popup_ProductionStadard_ChangePosition_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			IsDownPopup_ProductionStandard = false;
		}

		private void btn_Popup_ProductionStadard_ChangePosition_PreviewMouseMove(object sender, MouseEventArgs e)
		{
			if (IsDownPopup_ProductionStandard)
			{
				System.Windows.Point pos = e.GetPosition(Popup_ProductionStadard);
				Popup_ProductionStadard.HorizontalOffset += pos.X - OriginalPointPopup_ProductionStandard.X;
				Popup_ProductionStadard.VerticalOffset += pos.Y - OriginalPointPopup_ProductionStandard.Y;
				OriginalPointPopup_ProductionStandard = pos;
			}
		}











		#endregion		
	}
}
